React-native-fs: access content://com.android.providers.media.documents/document/image%3A99

Created on 26 Sep 2017  路  15Comments  路  Source: itinance/react-native-fs

I'm getting a content uri in android while using react-native-document-picker or react-native-contacts (for the avatars).
URIs like:
'content://com.android.providers.media.documents/document/image%3A99'
Trying to access this file fails with "File does not exist"

const urlDecoded = decodeURIComponent(url);
RNFS.stat(urlDecoded)
.then((file) => {
console.log("RNFS URL SUCCESS", file);
})
.catch((err) => {
console.log("RNFS URL ERROR", err);
});

Any idea how to access the file?
10x

feature-request

Most helpful comment

Hey @itinance, I just added a PR based on @jrichardlai's work. I hope we'll finally be able to work with content URI's on Android with no trouble! 馃檪

All 15 comments

Hi @EyalSi! The scheme "content://" is currently not supported.

PRs are very appreciated.

@itinance Does this still need to be resolved? I saw a PR request that could resolve it but I believe it was rejected?

I have the same error, any updates ?

I have a fix locally in my project; however, I am hesitant to create a PR request since there is one that does the same already pending.

@LukBowen which one do you mean?

PR #49

Yes, i remember. I turned back to the contributor but he never answered. I will modify this PR manually to keep backward compatibility alive.

Sorry, I didn't realize that was it was missing backwards compatibility. Other wise I would have just create my own PR.

Submitting your own PR would be a good option! I would merge quickly (while CET-timezone ;) )

I can still do it; however, it will have to be later today. Currently working on a separate project at work.

Great and many thanks. No rush :)

Hey @itinance, I just added a PR based on @jrichardlai's work. I hope we'll finally be able to work with content URI's on Android with no trouble! 馃檪

I've just tested the latest version (2.9.7) and it's working perfectly! THANKS!

It is not working for me.
I installed this package today hoping it will help me get the absolute file path but it is not working
my code is

DocumentPicker.show({ filetype: fileTypeArray }, (error,result) => {
        let uri = Platform.OS === "ios" ? result.uri.replace("file://", "") : `file://${result.uri}`;
        console.log(result)
        const fs = require("react-native-fs")
        fs.stat(decodeURIComponent(uri)).then(resp => {
            console.log(resp)
        })
        let file = {
            uri: result.uri,
            type: result.type,
            name: result.fileName,
            size: result.fileSize,
        }

and this is what I get

05-19 12:57:18.639  6494  7163 W ReactNativeJS: Possible Unhandled Promise Rejection (id: 0):
05-19 12:57:18.639  6494  7163 W ReactNativeJS: Error: File does not exist

Version: "react-native-fs": "^2.9.12",

content://com.android.providers.media.documents/document/image%3A400331
I got this when I uploaded an uri from my phone to firebase firestore ... any idea how to get the image from it?

Was this page helpful?
0 / 5 - 0 ratings