Delete file from storage using RNFetchBlob

3.3k views Asked by At

I have the following code to unlink/delete a file from the downloads folder I created also through the application using the same path.

Note I am using the RNFetchBlob package.

---
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);
      });
---

I keep getting the following error;

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

I thought it may have been the path but this is the same path I used to create the file and I can see the file via the File Explorer on Android.

Solution

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

There are 2 answers

0
Robin Rai On

Just add android:requestLegacyExternalStorage="true" in the AndroidManifiest.xml file

<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">
0
HassanHeydariNasab On