Skip to content

Commit 6520e09

Browse files
committed
Apply fix to #264
1 parent e7a0f89 commit 6520e09

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,32 @@ private void done(Response resp) {
500500
// It uses customized response body which is able to report download progress
501501
// and write response data to destination path.
502502
resp.body().bytes();
503+
503504
} catch (Exception ignored) {
504505
// ignored.printStackTrace();
505506
}
506507
this.destPath = this.destPath.replace("?append=true", "");
507-
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
508+
509+
try {
510+
long expectedLength = resp.body().contentLength();
511+
// when response contains Content-Length, check if the stream length is correct
512+
if(expectedLength > 0) {
513+
long actualLength = new File(this.destPath).length();
514+
if(actualLength != expectedLength) {
515+
callback.invoke("RNFetchBlob failed to write data to storage : expected " + expectedLength + " bytes but got " + actualLength + " bytes", null);
516+
}
517+
else {
518+
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
519+
}
520+
}
521+
else {
522+
callback.invoke(null, RNFetchBlobConst.RNFB_RESPONSE_PATH, this.destPath);
523+
}
524+
}
525+
catch (Exception err) {
526+
callback.invoke(err.getMessage());
527+
err.printStackTrace();
528+
}
508529
break;
509530
default:
510531
try {

0 commit comments

Comments
 (0)