react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Error: Directory could not be created

Open azizijunaid-zz opened this issue 4 years ago • 9 comments

 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!

azizijunaid-zz avatar Sep 02 '20 09:09 azizijunaid-zz

It gets fixed if you add android:requestLegacyExternalStorage="true" to your manifest in <application tag. 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.

JaioSkura avatar Sep 02 '20 16:09 JaioSkura

But i am storing in internal storage

azizijunaid-zz avatar Sep 03 '20 21:09 azizijunaid-zz

any fix for this?

raazatul7 avatar Dec 16 '20 12:12 raazatul7

@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

Cully-Curwen avatar Dec 21 '20 11:12 Cully-Curwen

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

请求权限

MwStar avatar Jan 28 '21 09:01 MwStar

Same issue i solved it by add requestLegacyExternalStorage in AndroidManifest

<manifest ... >

<application android:requestLegacyExternalStorage="true" ... > ...

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

wanxue0804 avatar Feb 23 '21 06:02 wanxue0804

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

thats work to me thanks alot

nathan-guedes avatar May 27 '21 02:05 nathan-guedes

Finally !! it works with me when change sdkverson in build.gradle to :-

        compileSdkVersion = 29
        targetSdkVersion = 29
``

AbanoubAshraaf avatar Dec 30 '21 20:12 AbanoubAshraaf

In the library RNFS, the RNFS.ExternalStorageDirectoryPath takes a path that is not allowed on version 11.

Use custom path, just replace ExternalStorageDirectoryPath with /storage/emulated/0/Android/media/{$packagename} Android for version below 10, your old code will work fine.

Original link https://stackoverflow.com/a/70195624/8098613

ahsan-abrar avatar Feb 15 '22 15:02 ahsan-abrar