rn-fetch-blob取消下载-承诺拒绝

时间:2020-10-22 11:57:24

标签: react-native fetch-api rn-fetch-blob

我使用rn-fetch-blob在React Native中下载文件 一切正常,但根据文档使用cancel method时,取消操作无效并出现错误“ fileFetchPromise无法定义”

我的代码:

const download = () => {
  let fileOptions = { fileCache: true, path: path, };
  const fileFetchPromise = config(fileOptions).fetch('GET', fileUrl);
  fileFetchPromise.progress({ interval : 1000 }, (received, total) => {
    let persend = 100 * received / total;
    setSaved(persend.toFixed(0));
    setReceived(bytesToSize(received));
    setTotalSize(bytesToSize(total));
  });

  fileFetchPromise.then((data) => {
    setSaved('100');
  }).catch((err) => {
    setSaved('0')
  })
}

const cancelDownload = () => {
  fileFetchPromise.cancel((err) => {})
}

如何取消(中止)获取?

0 个答案:

没有答案