소스 검색

Fix android stat bug when stat asset file

Ben Hsieh 8 년 전
부모
커밋
f307c698d9
2개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  1. 5
    1
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
  2. 3
    2
      src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+ 5
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 파일 보기

@@ -555,7 +555,11 @@ public class RNFetchBlobFS {
555 555
      */
556 556
     static void stat(String path, Callback callback) {
557 557
         try {
558
-            callback.invoke(null, statFile(path));
558
+            WritableMap result = statFile(path);
559
+            if(result == null)
560
+                callback.invoke("stat error: failed to list path `" + path + "` for it is not exist or it is not a folder", null);
561
+            else
562
+                callback.invoke(null, result);
559 563
         } catch(Exception err) {
560 564
             callback.invoke(err.getLocalizedMessage());
561 565
         }

+ 3
- 2
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java 파일 보기

@@ -199,7 +199,8 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
199 199
                     String filename = map.getString("filename");
200 200
                     // upload from storage
201 201
                     if(data.startsWith(filePathPrefix)) {
202
-                        File file = new File(data.substring(filePathPrefix.length()));
202
+                        String orgPath = data.substring(filePathPrefix.length());
203
+                        File file = new File(RNFetchBlobFS.normalizePath(orgPath));
203 204
                         form.addBinaryBody(name, file, ContentType.APPLICATION_OCTET_STREAM, filename);
204 205
                     }
205 206
                     // base64 embedded file content
@@ -228,7 +229,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
228 229
             // upload from storage
229 230
             if(body.startsWith(filePathPrefix)) {
230 231
                 String filePath = body.substring(filePathPrefix.length());
231
-                entity = new FileEntity(new File(filePath));
232
+                entity = new FileEntity(new File(RNFetchBlobFS.normalizePath(filePath)));
232 233
             }
233 234
             else {
234 235
                 blob = Base64.decode(body, 0);