I'm trying to save an image to document directory (instead of cache) using react native and react-native-fs library, but instead I get a blank photo.
const localPath = (image) => {
console.log("Cache directory path is ", image)
const fileName = image.split('/').pop();
console.log('Filename is ',fileName)
const newPath = 'file://' + RNFS.DocumentDirectoryPath + '/' + fileName;
console.log(newPath)
// write the file
RNFS.writeFile(newPath, image, 'base64')
.then((success) => {
console.log('IMG WRITTEN!');
console.log(newPath)
})
.catch((err) => {
console.log(err.message);
});
return newPath
}
So I want to use this newPath
<Image style={styles.image} source={{ uri: newPath }} />
but a blank photo appears..... If I pass the original path, then the photo is displayed.