react-native-fs
react-native-fs copied to clipboard
Unsupported Content URI
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}`)
} catch (e) {
console.log('save failed', e)
}
I got error on Android:
save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary%3ADocuments]
It seems stat
does not work on directory?
I've alread graint the permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
And set android:requestLegacyExternalStorage="true"
Here's my build.gradle
ext {
buildToolsVersion = "30.0.2"
minSdkVersion = 21
compileSdkVersion = 30
targetSdkVersion = 30
ndkVersion = "20.1.5948944"
}
same issue
same here
Any solution?
You need to decode the URL, notice the % in the path:
await RNFS.stat(decodeURIComponent(url.uri))
Same error after decode:
save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary:Documents]
解码后同样错误:
save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary:Documents]
have you solved this problem?