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 @@ -531,16 +531,26 @@ private void done(Response resp) {
531531 }
532532 break ;
533533 case FileStorage :
534+ ResponseBody responseBody = resp .body ();
535+
534536 try {
535537 // In order to write response data to `destPath` we have to invoke this method.
536538 // It uses customized response body which is able to report download progress
537539 // and write response data to destination path.
538- resp . body () .bytes ();
540+ responseBody .bytes ();
539541 } catch (Exception ignored ) {
540542// ignored.printStackTrace();
541543 }
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+ }
544554 break ;
545555 default :
546556 try {
Original file line number Diff line number Diff line change @@ -69,6 +69,10 @@ public long contentLength() {
6969 return originalBody .contentLength ();
7070 }
7171
72+ public boolean isDownloadComplete () {
73+ return bytesDownloaded == contentLength ();
74+ }
75+
7276 @ Override
7377 public BufferedSource source () {
7478 ProgressReportingSource countable = new ProgressReportingSource ();
You can’t perform that action at this time.
0 commit comments