Skip to content

Commit f836385

Browse files
author
Sushant Gupta
committed
Bug fix for download interruption promise rejection
1 parent d8c79f6 commit f836385

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+13-3
Original file line numberDiff line numberDiff 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 {

android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java

+4
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)