This repository was archived by the owner on Mar 16, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
src/android/src/main/java/com/RNFetchBlob Expand file tree Collapse file tree 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) {
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 {
You can’t perform that action at this time.
0 commit comments