Download large file with a weak network connection: resolves with status 200 when the file is not fully loaded
See original GitHub issueVersions
"react": "16.6.1",
"react-native": "0.57.5",
"rn-fetch-blob": "^0.10.13"
Problem I download the file to the device. When the Internet connection is weak or the connection is broken, the file download stops. But instead of an error, RNFetchBlob’s promise successfully resolves with 200 status code and has the path to the broken file.
Actual Behavior: RNFetchBlob’s promise successfully resolves with 200 status code when file was not fully downloaded
Expected Behavior: If the connection is broken, RNFetchBlob’s promise resolves with an error and I can catch the error in the .catch
block.
Code
return new Promise((resolve, reject) => {
RNFetchBlob
.config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache : true,
session : 'init',
path : path,
trusty : true
})
.fetch('get', url, {})
.progress((received, total) => {
if (OfflineMapDownloadService.isDBDownloading) {
this.progressCallback(received/total);
}
})
.then((res) => {
let status = res.info().status;
if(status === 200) {
resolve(res.path());
} else {
console.log(res);
reject(new Error('Invalid RN-blob status ' + status));
}
})
.catch((errorMessage, statusCode) => {
console.log(errorMessage);
Sentry.captureException(new Error(errorMessage));
reject(errorMessage);
});
});
Issue Analytics
- State:
- Created 4 years ago
- Comments:12
Top Results From Across the Web
Fix file download errors - Google Chrome Help
This error means that there's not enough space on your computer to download the file. To fix the error: Delete some files from...
Read more >How to deliver big files in ASP.NET Response? - Stack Overflow
This results in very slow start of file, as user downloads and even progress bar does not appear till few seconds, typically 3...
Read more >A Complete Guide and List of HTTP Status Codes
A complete list of HTTP status codes with explaination of what they are, why they occur and what you can do to fix...
Read more >Avoiding the Top 10 NGINX Configuration Mistakes
Errors include insufficient file descriptors per worker, disabling proxy buffering, and not using upstream groups and keepalive connections.
Read more >HTTP Status Codes List | HTTP Error Codes Explained
Status code 102 is an interim response code, telling the client that the server has accepted the full request, but has not completed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any updates on this issue? I’m still seeing this issue on both platforms (Android and IOS). To reproduce it, I just need to turn off wifi/4g during download and it can be a small file(not necessary a big file) like image with ~1mb size
Note also that
progress
won’t always finish withtotalBytes === downloadedBytes
with iOS either. However, iOS doesn’t seem to have this exact problem when attempted to resume; if the connection fails to resume the native (OS) code will timeout and RBFB will report that error.In conclusion; I don’t recommend comparing downloaded to total bytes for either platform without fixing the native code.