-
Notifications
You must be signed in to change notification settings - Fork 795
Description
Info:
rn-fetch-blob: 0.11.1
react-native: 0.61.1
platform: Android
Issue:
I keep getting the error from rn-fetch-blob: "RNFetchBlob failed. Download interrupted."
What:
I am trying to download a PDF that is sent from the server with Transfer-Encoding: chunked. Here is the response headers from curl (curl used to verify headers):
< HTTP/1.1 200 OK
< Content-Type: application/pdf
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< Cache-Control: private
< Referrer-Policy: strict-origin-when-cross-origin
< X-Permitted-Cross-Domain-Policies: none
< X-XSS-Protection: 1; mode=block
< X-Request-Id: 77793746-2596-4ea6-91d0-04a2a282efaf
< Content-Disposition: attachment; filename="C0RF196576.pdf"
< X-Download-Options: noopen
< Content-Transfer-Encoding: binary
< ETag: W/"79cf291140e5b219daa1387b23dd4476"
< X-Frame-Options: SAMEORIGIN
< X-Runtime: 2.455705
< X-Content-Type-Options: nosniff
< Date: Fri, 27 Sep 2019 00:51:57 GMT
< X-Powered-By: Phusion Passenger Enterprise 6.0.3
< Server: nginx/1.17.3 + Phusion Passenger 6.0.3
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< x-frame-options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< x-frame-options: SAMEORIGIN
< X-Content-Type-Options: nosniff
<
Inside rn-fetch-blob source code I see the following (RNFetchBlobReq.java):
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.
responseBody.bytes();
} catch (Exception ignored) {
ignored.printStackTrace();
}
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;
The rnFetchBlobFileResp.isDownloadComplete() is where it is failing. Inside that method we have (RNFetchBlobFileResp.java):
public boolean isDownloadComplete() {
return bytesDownloaded == contentLength();
}
And contentLength() we have (RNFetchBlobBody.java):
@Override
public long contentLength() {
return chunkedEncoding ? -1 : contentLength;
}
So unless I am reading this wrong, the contentLength for "chunked" encoding will always be -1, which will never match bytesDownloaded?
Am I reading this correctly? Doesn't this mean Transfer-Encoding: chunked downloads will always fail?