Skip to content

Commit

Permalink
Merge pull request #396 from sonudoo/download-interruption-android-bu…
Browse files Browse the repository at this point in the history
…gfix

Bug fix for download interruption promise rejection
  • Loading branch information
Traviskn authored Sep 26, 2019
2 parents d35fb73 + f836385 commit 4305ef8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 13 additions & 3 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,16 +530,26 @@ private void done(Response resp) {
}
break;
case FileStorage:
ResponseBody responseBody = resp.body();

try {
// In order to write response data to `destPath` we have to invoke this method.
// It uses customized response body which is able to report download progress
// and write response data to destination path.
resp.body().bytes();
responseBody.bytes();
} catch (Exception ignored) {
// ignored.printStackTrace();
}
this.destPath = this.destPath.replace("?append=true", "");
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);

RNFetchBlobFileResp rnFetchBlobFileResp = (RNFetchBlobFileResp) responseBody;

if(rnFetchBlobFileResp != null && rnFetchBlobFileResp.isDownloadComplete() == false){
callback.invoke("RNFetchBlob failed. Download interrupted.", null);
}
else {
this.destPath = this.destPath.replace("?append=true", "");
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
}
break;
default:
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public long contentLength() {
return originalBody.contentLength();
}

public boolean isDownloadComplete() {
return bytesDownloaded == contentLength();
}

@Override
public BufferedSource source() {
ProgressReportingSource countable = new ProgressReportingSource();
Expand Down

0 comments on commit 4305ef8

Please sign in to comment.