RNFS.stat(path) gives:
Possible Unhandled Promise Rejection (id: 0):
│ Error: File does not exist
│ createErrorFromErrorData@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1730:26
│ http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1689:51
│ __invokeCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2258:23
│ http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1984:34
│ __guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2172:15
│ invokeCallbackAndReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:1983:21
â”” invokeCallbackAndReturnFlushedQueue@[native code]
But RNFS.exists(path) says true for content:// file.
my problem too
I had solved this problem with use rn-fetch-blob.
I used react-native-fs for ios and rn-fetch-blob for android to get the file's absolute path.
`
import RNFetchBlob from 'rn-fetch-blob';
const RNFS = require('react-native-fs');
let file = await DocumentPicker.pick({
type: [DocumentPicker.types.allFiles],
});
if (Platform.OS === 'ios') {
const split = file.uri.split('/');
const name = split.pop();
const inbox = split.pop();
const realPath = `${RNFS.TemporaryDirectoryPath}${inbox}/${name}`;
file.path = decodeURI(realPath);
} else {
const newFile = await RNFetchBlob.fs.stat(file.uri);
file = newFile;
}
`
Thanks for your answer.
I'll try rn-fetch-blob
Hello
I tried with RNFetchBlob but I still have the issue when I use a react-native-document-picker.
Seems like uri like this one : content://com.android.providers.downloads.documents/document/.. are not accepted.
Same problem here
any updates?
https://github.com/itinance/react-native-fs/pull/899 should fix this.
Still happening for uris like content://com.android.providers.media.documents/document/image%3A38695
In my case, the path is:
file:/data/user/0/com.my.app/cache/ImagePicker/e9b7fa9f-96c9-4402-96ac-c2a9d679d4cf.jpg
and it says "Does not exists", but this only happens in android.
I'm trying to use this with expo-image-picker to validate the file size of the selected picture, I think it's unable to access the cache directory on android?
in my case it was just the file: on the path, I just need to remove that and it works as expected. I saw there's a related PR to this, which I think is so many years ago now https://github.com/itinance/react-native-fs/pull/49