Browse Source

Fix android stat bug when stat asset file

Ben Hsieh 8 years ago
parent
commit
f307c698d9

+ 5
- 1
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

@@ -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 View File

@@ -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);