Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Commit

Permalink
Apply fix to #264
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Feb 14, 2017
1 parent e7a0f89 commit 6520e09
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,32 @@ private void done(Response resp) {
// It uses customized response body which is able to report download progress
// and write response data to destination path.
resp.body().bytes();

} catch (Exception ignored) {
// ignored.printStackTrace();
}
this.destPath = this.destPath.replace("?append=true", "");
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);

try {
long expectedLength = resp.body().contentLength();
// when response contains Content-Length, check if the stream length is correct
if(expectedLength > 0) {
long actualLength = new File(this.destPath).length();
if(actualLength != expectedLength) {
callback.invoke("RNFetchBlob failed to write data to storage : expected " + expectedLength + " bytes but got " + actualLength + " bytes", null);
}
else {
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
}
}
else {
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
}
}
catch (Exception err) {
callback.invoke(err.getMessage());
err.printStackTrace();
}
break;
default:
try {
Expand Down

0 comments on commit 6520e09

Please sign in to comment.