1

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');
Aleksandar Zoric
  • 1,343
  • 3
  • 18
  • 45

2 Answers2

0

Use MANAGE_EXTERNAL_STORAGE permission as a quick solution (edit AndroidManifiest.xml)

https://developer.android.com/training/data-storage/manage-all-files

Or use more advanced techniques:

https://developer.android.com/training/data-storage/shared/media

https://developer.android.com/training/data-storage/shared/documents-files

-1

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">
Sven Eberth
  • 3,057
  • 12
  • 24
  • 29
Robin Rai
  • 1
  • 1