react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Unsupported Content URI

Open xionxiao opened this issue 3 years ago • 6 comments

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"
    }

xionxiao avatar Jan 02 '22 18:01 xionxiao

same issue

nejcet avatar Jan 07 '22 11:01 nejcet

same here

brunofariasd avatar Jan 08 '22 20:01 brunofariasd

Any solution?

tomgreco avatar Mar 20 '22 23:03 tomgreco

You need to decode the URL, notice the % in the path:

await RNFS.stat(decodeURIComponent(url.uri))

tallen11 avatar Jun 30 '22 23:06 tallen11

Same error after decode:

save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary:Documents]

xionxiao avatar Jul 01 '22 00:07 xionxiao

解码后同样错误:

save failed [Error: Unsupported Uri content://com.android.externalstorage.documents/tree/primary:Documents]

have you solved this problem?

helloworq avatar Sep 01 '23 03:09 helloworq