react-native-fs
react-native-fs copied to clipboard
RNFS.readDir sees the file but RNFS.copyFile says the file "doesn't exist".
- "react": 17.0.2
- "react-native": 0.67.2
- "react-native-fs": ^2.19.0
- "react-native-image-crop-picker": ^0.37.3
- iPhone 13 sim running iOS 15.4
I am using React Native Image Crop Picker
to select an image from the photo library and attempting to use RNFS.copyFile
command to copy this image to a specified directory.
RNFS.readDir
sees the file is there and I try to use the result.path from it to copy the file over but it says file doesn't exist.
Here is the code I'm using:
if (image) {
let imagePath = String(image).split('/');
let imageName = imagePath.pop();
let pathString = imagePath.join('/');
RNFS.readDir(pathString)
.then((result) => {
for (let i = 0; i < result.length; i++) {
if (result[i].name === imageName) {
console.log("Found selected image: " + result[i].path)
RNFS.copyFile(result[i].path, vehicleImagesPath + vehicleId + ".jpg")
.then(() => {
console.log("==> Vehicle image saved");
})
.catch((error) => {
console.log("==> Vehicle image NOT saved: " + error.message);
});
}
}
})
.catch((error) => {
console.log("No Dir Found --- " + image)
});
}
And here is the output I'm getting:
Found selected image: /Users/XXXXXXX/Library/Developer/CoreSimulator/Devices/13217381-22BA-459C-84C2-81E7F075D228/data/Containers/Data/Application/4FE78B68-643F-4F75-ADA3-2AF34B0C6FEC/tmp/react-native-image-crop-picker/4304270C-A5E8-4329-B586-A4139CDE8634.jpg
==> Vehicle image NOT saved: The file “4304270C-A5E8-4329-B586-A4139CDE8634.jpg” doesn’t exist.
So it's clearly seeing the file but RNFS.copyFile
is having an issue finding it.
@pasllani Were you able to fix this?
This functionality is surprisingly broken lol. I think it's writing to a directory it doesn't have access to read from.
So what I ended up doing is using the includeBase64
property when using ImagePicker.openCamera
or ImagePicker.openPicker
.
Then I took that base64 data from image.data
and saved it using RNFS.writeFile("imagePath", image, 'base64')
.
This method may be a LOT slower since we're storing base64 data directly. Have yet to test it on a large data set.
So for now this functionality is STILL BROKEN. This is just a temporary workaround.
@pasllani-USX Will surely check the workaround you told. Thanks for your response.
same here
same here
same
Same issue.Not getting file which is located in application.My image path is 'Users/*******/Documents/reactProjs/CodeStructure/src/assets/icons/icon_collectibles.jpeg
if I put statically it works but I want to set it dynamically.Is it possible for iOS?