react-native-fs
react-native-fs copied to clipboard
Error: Directory could not be created
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!
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.
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
<manifest ... >
<application android:requestLegacyExternalStorage="true" ... > ...
when i saw it from rn-fetch-blob here the same issue
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
Finally !! it works with me when change sdkverson in build.gradle to :-
compileSdkVersion = 29
targetSdkVersion = 29
``
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