react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Stat says "File does not exist"

Open FrankFundel opened this issue 6 years ago • 20 comments
trafficstars

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.

FrankFundel avatar Sep 14 '19 18:09 FrankFundel

my problem too

ENategh avatar Sep 23 '19 12:09 ENategh

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;

}

`

Helongzhou avatar Nov 18 '19 09:11 Helongzhou

Thanks for your answer. I'll try rn-fetch-blob

deiv23 avatar Nov 18 '19 11:11 deiv23

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.

kilaniamine96 avatar May 22 '20 11:05 kilaniamine96

Same problem here

bdbch avatar Jun 08 '20 08:06 bdbch

any updates?

arthedza avatar Jun 09 '20 15:06 arthedza

https://github.com/itinance/react-native-fs/pull/899 should fix this.

songsterq avatar Jun 30 '20 21:06 songsterq

Still happening for uris like content://com.android.providers.media.documents/document/image%3A38695

blgastesi avatar Dec 30 '20 12:12 blgastesi

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

aprilmintacpineda avatar Feb 06 '21 15:02 aprilmintacpineda

Still happening for uris like content://com.android.providers.media.documents/document/image%3A38695

which solution worked for you.

siddharth-kt avatar Jul 05 '21 05:07 siddharth-kt

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 avatar Aug 25 '21 14:08 enigmablue

@enigmablue sorry for the delay, but you cannot read Download directory contents ,it is forbidden by android os

arcollector avatar Jun 28 '22 20:06 arcollector

@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 avatar Jun 30 '22 23:06 tallen11

@tallen11 I dunno I highly recommend to everyone to leave this library and start using react-native-file-access asap

arcollector avatar Jul 01 '22 03:07 arcollector

@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.

tallen11 avatar Jul 01 '22 03:07 tallen11

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.

lekbit avatar Jun 21 '23 22:06 lekbit

Any solution folks? Nothing works for me when comes content://

This is happening on xiaomi.

talesmgodois avatar Jan 11 '24 04:01 talesmgodois