I'm using react-native-document-picker
to pick up a folder and using react-native-fs
to save a file to that folder. Since react-native-document-picker
returns a content uri not absolute path. I use stat
to get the real path.
try {
const url = await DocumentPicker.pickDirectory()
const stat = await RNFS.stat(`${url.uri}`)
RNFS.writeFile(`${stat.path}/output.txt`, content, 'ascii')
} catch (e) {
console.log('save failed', e)
}
I got error on Android (buildToolsVersion = "30.0.2", targetSdkVersion = 30 ):
save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary%3ADocuments]
I've alread granted the external read/write permissions and set ndroid:requestLegacyExternalStorage="true"
in AndroidManifest.xml
Then how to convert the Content:// uri to real path and save file in it?