I am trying to overwrite an image with a new image on Ios works perefctly, but on android it only creates the file the first time and then you cannot ovewrite it. I tried react-native-fs, expo-file-system and rn-fetch-blob, all give me the same result. I am using android 10 on real device and android 12 simulator.
react-native-fs
const path = "file://" + RNFS.DocumentDirectoryPath + "/sign.png";
RNFS.writeFile(
path,
signature.replace("data:image/png;base64,", ""),
"base64"
)
.then(() => {
dispatch(createSignature(path));
})
.catch(console.error);
expo
const path = FileSystem.cacheDirectory + "sign.png";
FileSystem.writeAsStringAsync(
path,
signature.replace("data:image/png;base64,", ""),
{ encoding: FileSystem.EncodingType.Base64 }
)
.then(() => FileSystem.getInfoAsync(path))
.then(() => dispatch(createSignature(path)))
.catch(console.error);
setSign(signature);
rn-fetch-blob
RNFetchBlob.fs
.writeFile(
`${RNFetchBlob.fs.dirs.DocumentDir}/sign.png`,
signature.replace("data:image/png;base64,", ""),
"base64"
)
.then(() => {
dispatch(createSignature(path));
})
.catch((e) => console.log(e));