react-native-fs: Stat says "File does not exist"
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.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 8
- Comments: 17
I am stuck with a file like this
content://com.android.providers.downloads.documents/document/msf:12
Nothing from RNFS works (neither stat, nor copy file) and it hits this
Permission Denial: reading com.android.providers.downloads.DownloadStorageProvider uri content://com.android.providers.downloads.documents/document/msf:12 from pid=7862, uid=10101 requires that you obtain access using ACTION_OPEN_DOCUMENT or related APIs
Anyone has solution?
Getting this when on Google Pixel 3a
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.
Still happening for uris like
content://com.android.providers.media.documents/document/image%3A38695
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’);
`
@tallen11 I dunno I highly recommend to everyone to leave this library and start using react-native-file-access asap
In my case, the path is:
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?
Edit
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/49my problem too