React-native-fs: Error: Directory could not be created

Created on 2 Sep 2020  路  6Comments  路  Source: itinance/react-native-fs

 let localSong = `${RNFS.DocumentDirectoryPath}/${await RNFS.mkdir(`
          ${RNFS.DocumentDirectoryPath}/${name}`)}/${fileName}`;

I am having this issue i am not able to create directory RNFS.mkdir if anyone have solved so please help me!

Most helpful comment

It gets fixed if you add
android:requestLegacyExternalStorage="true"
to your manifest in This opts you into the legacy storage model, and your existing external storage code will work. It seems that this fix will not work on Android R and higher though, so this is only a short-term fix.

All 6 comments

It gets fixed if you add
android:requestLegacyExternalStorage="true"
to your manifest in This opts you into the legacy storage model, and your existing external storage code will work. It seems that this fix will not work on Android R and higher though, so this is only a short-term fix.

But i am storing in internal storage

any fix for this?

@azizijunaid

 let localSong = `${RNFS.DocumentDirectoryPath}/${await RNFS.mkdir(`
          ${RNFS.DocumentDirectoryPath}/${name}`)}/${fileName}`;

I am having this issue i am not able to create directory RNFS.mkdir if anyone have solved so please help me!

I believe your problem is because RNFS.mkdir returns void

mkdir(filepath: string, options?: MkdirOptions): Promise<void>

I would create the directory separately, then create the path for let localSong

import {
  PermissionsAndroid,
} from "react-native";
async function checkAndroidPermission() {
  try {
    const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
    await PermissionsAndroid.request(permission);
    Promise.resolve();
  } catch (error) {
    Promise.reject(error);
  }
}

璇锋眰鏉冮檺

Same issue
i solved it by add requestLegacyExternalStorage in AndroidManifest


...

when i saw if from rn-fetch-blob here
the same issue

Was this page helpful?
0 / 5 - 0 ratings