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
      */
555
      */
556
     static void stat(String path, Callback callback) {
556
     static void stat(String path, Callback callback) {
557
         try {
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
         } catch(Exception err) {
563
         } catch(Exception err) {
560
             callback.invoke(err.getLocalizedMessage());
564
             callback.invoke(err.getLocalizedMessage());
561
         }
565
         }

+ 3
- 2
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java View File

199
                     String filename = map.getString("filename");
199
                     String filename = map.getString("filename");
200
                     // upload from storage
200
                     // upload from storage
201
                     if(data.startsWith(filePathPrefix)) {
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
                         form.addBinaryBody(name, file, ContentType.APPLICATION_OCTET_STREAM, filename);
204
                         form.addBinaryBody(name, file, ContentType.APPLICATION_OCTET_STREAM, filename);
204
                     }
205
                     }
205
                     // base64 embedded file content
206
                     // base64 embedded file content
228
             // upload from storage
229
             // upload from storage
229
             if(body.startsWith(filePathPrefix)) {
230
             if(body.startsWith(filePathPrefix)) {
230
                 String filePath = body.substring(filePathPrefix.length());
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
             else {
234
             else {
234
                 blob = Base64.decode(body, 0);
235
                 blob = Base64.decode(body, 0);