diff --git a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java index 369b9baaf..473455e94 100644 --- a/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java +++ b/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java @@ -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 { diff --git a/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java b/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java index e4f725777..18ba47981 100644 --- a/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java +++ b/android/src/main/java/com/RNFetchBlob/Response/RNFetchBlobFileResp.java @@ -69,6 +69,10 @@ public long contentLength() { return originalBody.contentLength(); } + public boolean isDownloadComplete() { + return bytesDownloaded == contentLength(); + } + @Override public BufferedSource source() { ProgressReportingSource countable = new ProgressReportingSource();