itinance / itinance/react-native-fs

Can't read file from downloads with uri on Android

Open
#882 6 comments 3 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Hello,

RNFs version used : 2.16.6

I am trying to read the size of a document with RNFS.stat.

```
DocumentPicker.pick({
type: [DocumentPicker.types.pdf],
}).then((res) => {
RNFS.stat(res.uri).then((result) => {
console.log(${result.size});
}).catch((e) => {
console.log("Read dir error", e);
});
console.log(
\nuri : ${res.uri} \n
type : ${res.type} \n
name : ${res.name} \n
size : ${res.size} octets \n

);
```

It's working well on iOS and the value of res.uri is like this: "file:///private/var/mobile/Containers/Data/Application/..."

On Android I get an "Error: File does not exist". The uri in Android looks like : "content://com.android.providers.downloads.documents/document/3627". It seems like RNFS can't use Android Uri to read a file. The thing is I can only get this uri since it's coming from another library react-native-document-picker. The DocumentPicker does not provide a filepath.

Do you know a way to read, save or write a document when we only have its uri on Android, without having to write native java code ?

Thank you

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.