I've been struggling to solve this issue. I am using RN 0.61.5, react-native-document-picker 3.4.0, react-native-fs 2.16.6 and rn-fetch-blob 0.12.0. Tested in real device - iPhone 5s.
Objective:I want to check if the given uri exist in iOS.
Input value for uri: file:///private/var/mobile/Containers/Data/Application/2918F777-93D8-4256-9CF1-583AFB57456A/tmp/com.appname-Inbox/file-name.extension
. I got this uri from the return value of react-native-document-picker.
Trial:
let uri = 'file:///private/var/mobile/Containers/Data/Application/2918F777-93D8-4256-9CF1-583AFB57456A/tmp/com.appname-Inbox/file-name.extension';uri = decodeURIComponent(uri); // to deal with file name that contain spaceconst rnfsRead = await RNFS.read(uri, fileSize, 0, 'ascii');// works only first trial. If I change the uri with a random string, it definitely will return ENOENT file not found.// But, when I use the "real uri" again, it keeps return ENOENT. idk why this is happenconst rnfsReadFile = await RNFS.readFile(uri, 'ascii'); // the result and behaviour is same as using RNFS.readconst rnFetchBlobExist = await RNFetchBlob.fs.exists(uri); // always return falseconst rnfsExists = await RNFS.exists(uri); // always return false
FYI, below code is what I use for the Android
const uri = 'content://com.android.providers.media.documents/document/xxxx';const rnFetchBlobExist = await RNFetchBlob.fs.exists(uri); // return the right value (true if exist and false if not)
Any help would be very helpful!