通过反应native fetch blob删除下载的图像?

时间:2018-04-02 15:39:28

标签: react-native unlink react-native-fetch-blob

我使用RNFetchBlob以base64格式共享图像。但是图像正在我的本地文件夹中下载。我想删除它。根据我的研究知识,我想取消图像路径的链接。我不知道该怎么做。这是我的代码

_downloadImageAndShare(url ,title, message) {
const { fs } = RNFetchBlob.fs;
const self = this;
RNFetchBlob.config({ fileCache: true })
  .fetch('GET', url)
  .then(resp => resp.readFile('base64')
      .then(base64 => ({ resp, base64 })))
  .then(obj => {
    const headers = obj.resp.respInfo.headers;
    const type = headers['Content-Type'];
    const dataUrl = 'data:' + type + ';base64,' + obj.base64;
    return { url: dataUrl, title, message };

  })
  .then(options => Share.open(options)).catch(err => {err && 
  console.log(err); })         
}

如何在此方法中使用此代码

RNFetchBlob.fs.unlink(path)
.then(() => { ... })
.catch((err) => { ... })

以及如何指定unlink(path)??

提前感谢。

1 个答案:

答案 0 :(得分:0)

您可以使用config参数{/ 1}指定文件位置。

path

然后你可以像这样打电话给const filePath = RNFetchBlob.fs.dirs.DocumentDir + '/myFile'; RNFetchBlob.config({ fileCache: true, path : filePath }) .fetch('GET', url) .then(resp => resp.readFile('base64') .then(base64 => ({ resp, base64 }))) .then(obj => { const headers = obj.resp.respInfo.headers; const type = headers['Content-Type']; const dataUrl = 'data:' + type + ';base64,' + obj.base64; return { url: dataUrl, title, message }; }) .then(options => Share.open(options)).catch(err => {err && console.log(err); }) }

unlink
相关问题