itinance / itinance/react-native-fs

Cannot write to SD card outside of app dir

Open
#420 6 comments 1 reaction 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Hi. Thanks for the plugin. I am having an issue, which I'm assuming is permissions-related. I need to save some data on a physical SD card that persists after the app is removed, so I need to save it outside of the `Android/data/com.example/` directory. My app will only ever be installed on one type of device, so I can hard-code the path. I have no trouble writing to the apps' private directory on the card, but if I try to create a directory elsewhere then it fails.

My manifest includes:
```xml

```
..and checking dynamically shows the permission as available:

```javascript
const directory = await getSdCardDirectory();
// /mnt/m_external_sd/Android/media/hrp
if (!await RNFS.exists(directory)) {
console.log("doesn't exist", directory);
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, {
title: "Grant SD card access",
message: "We need access",
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Permission OK");
} else {
console.log("Permission failed");
}
if (await RNFS.mkdir(directory)) {
console.log("Directory created", directory);
} else {
console.warn("Could not create", directory);
}
} catch (err) {
console.warn("Create directory error", err);
}

}
```
This shows "Permission OK", but throws "Error: Directory could not be created"

Can anyone help? Thanks.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.