【问题标题】:Delete file from storage using RNFetchBlob使用 RNFetchBlob 从存储中删除文件
【发布时间】:2020-10-02 13:28:40
【问题描述】:

我有以下代码可以从我创建的下载文件夹中取消链接/删除一个文件,也可以通过应用程序使用相同的路径。

注意我使用的是 RNFetchBlob 包。

---
const fs = RNFetchBlob.fs
const base64 = RNFetchBlob.base64
const dirs = RNFetchBlob.fs.dirs

RNFetchBlob.fs
      .unlink(dirs.DownloadDir + '/passpoint.config.xml')
      .then(() => {
        alert("File deleted");
      })
      .catch(err => {
        alert(err);
      });
---

我不断收到以下错误;

[Error: Failed to delete '/storage/emulated/0/Download/passpoint.config.xml']

我以为它可能是路径,但这与我用来创建文件的路径相同,我可以通过 Android 上的文件资源管理器查看该文件。

解决方案

fs.unlink(dirs.DownloadDir + '/passpoint.config.xml');

【问题讨论】:

    标签: android react-native filesystems rn-fetch-blob


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      只需在 AndroidManifiest.xml 文件中添加android:requestLegacyExternalStorage="true"

      <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:requestLegacyExternalStorage="true">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-06-03
        • 2021-07-07
        • 2017-02-01
        • 1970-01-01
        • 2021-02-25
        • 1970-01-01
        • 2019-10-14
        • 2011-07-26
        相关资源
        最近更新 更多