Ben Hsieh 8 лет назад
Родитель
Сommit
5e5a461925

+ 6
- 6
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Просмотреть файл

@@ -94,11 +94,10 @@ public class RNFetchBlobFS {
94 94
                         }
95 95
                         FileInputStream fin = new FileInputStream(src);
96 96
                         byte [] buffer = new byte [10240];
97
-                        int read = fin.read(buffer);
98
-                        written = read;
99
-                        while(read > 0) {
97
+                        int read;
98
+                        written = 0;
99
+                        while((read = fin.read(buffer)) > 0) {
100 100
                             fout.write(buffer, 0, read);
101
-                            read = fin.read(buffer);
102 101
                             written += read;
103 102
                         }
104 103
                         fin.close();
@@ -798,8 +797,9 @@ public class RNFetchBlobFS {
798 797
             byte [] b = Base64.decode(data, Base64.NO_WRAP);
799 798
             if(encoding.toLowerCase().contains("urlencode")) {
800 799
                 try {
801
-                    b = URLDecoder.decode(new String(b), "UTF-8").getBytes();
802
-                } catch (UnsupportedEncodingException e) {
800
+                    String encoded = URLDecoder.decode(new String(b), "UTF-8");
801
+                    b = encoded.getBytes();
802
+                } catch (Exception e) {
803 803
                     e.printStackTrace();
804 804
                 }
805 805
             }

+ 5
- 6
src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Просмотреть файл

@@ -98,7 +98,7 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
98 98
     public boolean reportUploadProgress = false;
99 99
 
100 100
     public RNFetchBlobReq(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, ReadableArray arrayBody, final Callback callback) {
101
-        this.method = method;
101
+        this.method = method.toUpperCase();
102 102
         this.options = new RNFetchBlobConfig(options);
103 103
         this.taskId = taskId;
104 104
         this.url = url;
@@ -404,14 +404,13 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
404 404
                         String dest = RNFetchBlobFS.getTmpPath(ctx, taskId);
405 405
                         InputStream ins = resp.body().byteStream();
406 406
                         FileOutputStream os = new FileOutputStream(new File(dest));
407
+                        int read;
407 408
                         byte [] buffer = new byte[10240];
408
-                        int read = ins.read(buffer);
409
-                        os.write(buffer,0,read);
410
-                        while(read > 0) {
411
-                            os.write(buffer,0,read);
412
-                            read = ins.read(buffer);
409
+                        while ((read = ins.read(buffer)) != -1) {
410
+                            os.write(buffer, 0, read);
413 411
                         }
414 412
                         ins.close();
413
+                        os.flush();
415 414
                         os.close();
416 415
                         callback.invoke(null, null, dest);
417 416
                     }

+ 4
- 1
src/ios/RNFetchBlobFS.m Просмотреть файл

@@ -229,7 +229,10 @@ NSMutableDictionary *fileStreams = nil;
229 229
             if([encoding containsString:@"urlencode"])
230 230
             {
231 231
                 NSString * decode = [[[NSString alloc] initWithData:content encoding:NSUTF8StringEncoding] stringByRemovingPercentEncoding];
232
-                content = [decode dataUsingEncoding:NSUTF8StringEncoding];
232
+                if(decode != nil)
233
+                {
234
+                    content = [decode dataUsingEncoding:NSUTF8StringEncoding];
235
+                }
233 236
             }
234 237
         }
235 238
         else if([encoding isEqualToString:@"uri"]) {