File tree 1 file changed +22
-1
lines changed
src/android/src/main/java/com/RNFetchBlob
1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -500,11 +500,32 @@ private void done(Response resp) {
500
500
// It uses customized response body which is able to report download progress
501
501
// and write response data to destination path.
502
502
resp .body ().bytes ();
503
+
503
504
} catch (Exception ignored ) {
504
505
// ignored.printStackTrace();
505
506
}
506
507
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
+ }
508
529
break ;
509
530
default :
510
531
try {
You can’t perform that action at this time.
0 commit comments