react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Error in Cancel download process !

Open Pardeep03315 opened this issue 6 years ago • 2 comments

Hi , thanks for the awesome library . I am using this library last 2 month ...its really awesome thanks for maintaining this . . . . I have an issue in cancel download process . I an cancelling download process by jobId created on download begin callback first time . by the following code .

RNFS.stopDownload(jobId).then((res)=> { console.log("Download Cancelled : "+JSON.stringify(res)) }) .catch((res)=> { console.log("Error : "+res) })

But some error display in this method . Please suggest me ...is am i doing something wrong in logic ?? Please help s

Here is the screenshot

Pardeep03315 avatar Oct 15 '19 06:10 Pardeep03315

@Pardeep03315 RNFS.stopDownload does not return a promise (see docs and https://github.com/itinance/react-native-fs/issues/37 and https://github.com/itinance/react-native-fs/issues/355).

Also, for some reason the error is thrown at the RNFS.downloadFile level:

RNFS.downloadFile
  .promise
  .then((res) => {
    // all good
  })
  .catch((err) => {
    if (err.code === 'EUNSPECIFIED' && jobId === -1) return; // process was cancelled
    // else handle error
  })

stebogit avatar Aug 30 '20 16:08 stebogit

Whoever will face this problem, here is patch-package file with fix. It is simple fix that might contain possible race condition in combination with resumable downloads, but if you are not using that, should be fine.

Additionally this might throw generic error (not cancel specific one - FYI)

react-native-fs+2.20.0.patch

jibeleck avatar Jul 27 '25 09:07 jibeleck