Skip to content

Commit

Permalink
Bug fix for download interruption promise rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sushant Gupta committed Jul 7, 2019
1 parent d8c79f6 commit f836385
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 @@ -531,16 +531,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 @@ -69,6 +69,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 f836385

Please sign in to comment.