react-native-fs
react-native-fs copied to clipboard
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.
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?
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/49
Still happening for uris like
content://com.android.providers.media.documents/document/image%3A38695
which solution worked for you.
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
@enigmablue sorry for the delay, but you cannot read Download directory contents ,it is forbidden by android os
@enigmablue sorry for the delay, but you cannot read Download directory contents ,it is forbidden by android os
I don't know about the downloads directory, but I'm getting the exact same error trying to read from the plain old documents directory (on Android). The stat included in https://github.com/joltup/rn-fetch-blob works so it should be possible in theory for this library to work too. Problem is rn-fetch-blob causes a dependency conflict with react-native-pdf so I can't use it.
@tallen11 I dunno I highly recommend to everyone to leave this library and start using react-native-file-access asap
@tallen11 I dunno I highly recommend to everyone to leave this library and start using react-native-file-access asap
This looks promising, I'll take a look tomorrow, thanks.
Thanks to this react-native-scoped-storage, you can select the directory to save the file, create a file, fill the file. In general, this library can replace all other libraries like RNFS, react-native-document-picker.
Any solution folks? Nothing works for me when comes content://
This is happening on xiaomi.