Open teamtechalpha opened 5 years ago
up
+1 @rabanos-rvc @teamtechalpha did you people manage to solve it?
Actually, the problem lies in DownloadManager rather than RN-fetch blob itself, so the basic problem is that Rn fetch blob use download manager to do downloading but the issue is with whenever your download API throws an exception with status code 500
, instead of returning BroadCastReceiver they again retry that request until a maximum retry count, so if you will leave the enqueued download for some time, you would see that Rn fetch blob will resolve that promise.
So In short a workaround from the given Stackoverflow question could be in our RnFetchBlobReq.java
we can make some modification where we can query download manager at some interval and we can handle if DownloadManager.STATUS_PAUSED
then we can resolve the promise. Because I found out that whenever Api returns 500 download manager waits to retry which has this value.so it can solve our problem if our API is returning 500 server error,but i don't know if its a reliable solution or not.but it worked for me,I ll be posting code snippet in a while.
Also one quick solution could be without changing your code,is you can check at the API end and make sure your returning status code 200 400 etc but not 500!!
For reference - https://stackoverflow.com/questions/39745724/downloadmanager-broadcastreceiver-not-called-on-a-500-error-waiting-to-retry https://stackoverflow.com/questions/34782965/downloadmanager-understanding-error-http-data-error
Hi ! Thank you for reporting an issue, but we would like to remind you, we have a trouble shooting page in our wiki. You may want to take a look on that page or find issues tagged "trouble shooting" :p
let dir = Platform.OS === "android" ? RNFS.ExternalStorageDirectoryPath : RNFetchBlob.fs.dirs.DocumentDir; let path = dir +
${DOWNLOAD_FOLDER}/download.zip`;//Storing file in /storage/emulated/0/downloaded_content/download.zip
this.downloadTask = RNFetchBlob .config({ IOSBackgroundTask: true, addAndroidDownloads: { useDownloadManager: true, notification: true, mime: 'application/zip', path: path }, path: path, appendExt: 'zip' }) .fetch('GET', URL) .progress({ count: 10 }, (received, total) => { console.log(
Total ${total}, Received ${received}
);`
Download gets stuck in queued state, after debugging using android studio, download manager throws Path apperars to be invalid, this is not handled in module and thus our app gets stuck in downloading state, no notification is shown as well.