Selaa lähdekoodia

Bug fix for download interruption promise rejection

Sushant Gupta 5 vuotta sitten
vanhempi
commit
f836385b10

+ 13
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Näytä tiedosto

@@ -531,16 +531,26 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
531 531
                 }
532 532
                 break;
533 533
             case FileStorage:
534
+                ResponseBody responseBody = resp.body();
535
+
534 536
                 try {
535 537
                     // In order to write response data to `destPath` we have to invoke this method.
536 538
                     // It uses customized response body which is able to report download progress
537 539
                     // and write response data to destination path.
538
-                    resp.body().bytes();
540
+                    responseBody.bytes();
539 541
                 } catch (Exception ignored) {
540 542
 //                    ignored.printStackTrace();
541 543
                 }
542
-                this.destPath = this.destPath.replace("?append=true", "");
543
-                callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
544
+
545
+                RNFetchBlobFileResp rnFetchBlobFileResp = (RNFetchBlobFileResp) responseBody;
546
+
547
+                if(rnFetchBlobFileResp != null && rnFetchBlobFileResp.isDownloadComplete() == false){
548
+                    callback.invoke("RNFetchBlob failed. Download interrupted.", null);
549
+                }
550
+                else {
551
+                    this.destPath = this.destPath.replace("?append=true", "");
552
+                    callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
553
+                }
544 554
                 break;
545 555
             default:
546 556
                 try {

+ 4
- 0
android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java Näytä tiedosto

@@ -69,6 +69,10 @@ public class RNFetchBlobFileResp extends ResponseBody {
69 69
         return originalBody.contentLength();
70 70
     }
71 71
 
72
+    public boolean isDownloadComplete() {
73
+        return bytesDownloaded == contentLength();
74
+    }
75
+
72 76
     @Override
73 77
     public BufferedSource source() {
74 78
         ProgressReportingSource countable = new ProgressReportingSource();