react-native-fs: Stat says "File does not exist"

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 8
  • Comments: 17

Most upvoted comments

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’);

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;

}

`

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

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

my problem too