itinance / itinance/react-native-fs
SAF Support
- Dominant language
- C++
- Stars
- 5k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Does the project have any ability to support SAF read/writes? I've tried using a SAF Directory Picker I wrote:
https://github.com/oceanbit-dev/react-native-directory-picker/blob/master/android/src/main/java/com/rndirectorypicker/DirectoryPickerModule.java
But whenever utilizing the `writeFile` or `readFile`, I seem to always get errors since the paths cannot be converted from SAF to `/typical/paths/like/this`. SAF is required as-of Android R, and once React Native apps hit API 30 support, apps that aren't using SAF will likely break (such as mine).
Here's the relevant code to outline what I'm doing:
```
const [safPath, setSafPath] = React.useState('');
const pickSAFPath = () => {
NativeModules.DirectoryPickerSAFModule.selectDirectory((path) =>
setSafPath(path),
);
};
const writeToFileSAF = () => {
RNFS.writeFile(`${safPath}/test.txt`, 'Lorem ipsum dolor sit amet', 'utf8')
.then(() => {
console.log('FILE WRITTEN!');
showAlert();
})
.catch((err) => console.error(err));
};
```
Then, when I run `writeToFileSAF`, I get an error similar to the following:
```
[Error: ENOENT: Failed to open for writing: java.io.FileNotFoundException: open failed: EISDIR (Is a directory), open 'content://com.android.externalstorage.documents/tree/primary%3ADocuments/document/primary%3ADocuments/test.txt']
```

Are there known bugs regarding SAF? What's the future of this package look like?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.