File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
android/src/main/java/com/RNFetchBlob Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -530,16 +530,26 @@ private void done(Response resp) {
530530 }
531531 break ;
532532 case FileStorage :
533+ ResponseBody responseBody = resp .body ();
534+
533535 try {
534536 // In order to write response data to `destPath` we have to invoke this method.
535537 // It uses customized response body which is able to report download progress
536538 // and write response data to destination path.
537- resp . body () .bytes ();
539+ responseBody .bytes ();
538540 } catch (Exception ignored ) {
539541// ignored.printStackTrace();
540542 }
541- this .destPath = this .destPath .replace ("?append=true" , "" );
542- callback .invoke (null , RNFetchBlobConst .RNFB_RESPONSE_PATH , this .destPath );
543+
544+ RNFetchBlobFileResp rnFetchBlobFileResp = (RNFetchBlobFileResp ) responseBody ;
545+
546+ if (rnFetchBlobFileResp != null && rnFetchBlobFileResp .isDownloadComplete () == false ){
547+ callback .invoke ("RNFetchBlob failed. Download interrupted." , null );
548+ }
549+ else {
550+ this .destPath = this .destPath .replace ("?append=true" , "" );
551+ callback .invoke (null , RNFetchBlobConst .RNFB_RESPONSE_PATH , this .destPath );
552+ }
543553 break ;
544554 default :
545555 try {
Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ public long contentLength() {
6868 return originalBody .contentLength ();
6969 }
7070
71+ public boolean isDownloadComplete () {
72+ return bytesDownloaded == contentLength ();
73+ }
74+
7175 @ Override
7276 public BufferedSource source () {
7377 ProgressReportingSource countable = new ProgressReportingSource ();
You can’t perform that action at this time.
0 commit comments