Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 是否通过react native fetch blob删除下载的图像?_React Native_Unlink_React Native Fetch Blob - Fatal编程技术网

React native 是否通过react native fetch blob删除下载的图像?

React native 是否通过react native fetch blob删除下载的图像?,react-native,unlink,react-native-fetch-blob,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) .t

我正在使用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) => { ... })
如何指定取消链接(路径)


提前感谢。

您可以使用
config
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

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

那么+'/myFile'将是什么呢@但我不知道文件名。。。这是一个来自服务的url,您不必这样做。您可以保存在这个文件名中。我把它保留为“/myFile”好吗?