File '(null)' isn't writable Exception (EXPO IOS) React Native

Viewed 885

i'm developing an expo app in which i'm generating QR Code.i'm getting base64 string which i can save as jpg or png in gallery/album.so far, On android it is working fine as expected.But On IOS it is giving this Error

File '(null)' isn't writable

  • node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:103:50 in promiseMethodWrapper
  • node_modules/@unimodules/react-native-adapter/build/NativeModulesProxy.native.js:15:23 in moduleName.methodInfo.name
  • node_modules/expo-file-system/build/FileSystem.js:50:17 in writeAsStringAsync

I'm using expo FileSystem method writeAsStringAsync() Here is my Code.

const filename = FileSystem.documentDirectory + `${imageName}.jpg`; 
                let newFile = decodeURI(filename).replace('file://', '') ;
                console.log(newFile)
                FileSystem.writeAsStringAsync(filename, base64Code, {
                    encoding: FileSystem.EncodingType.Base64,
                }).then(()=>{
                    console.log('worked')
                }).catch((e)=>{
                    console.log(e)
                }); 
                await MediaLibrary.saveToLibraryAsync(filename).then(()=>{ 
                        setIsSavedGallery(true);
                        setTimeout(showAlertGallery, 1000);
                }).catch((e)=>{
                    console.log(e)
                }); 

any clue on this error? how can i fix? what i'm doing wrong? i can't seem to understand. any kind of help would be appreciated. Thanks

1 Answers

I had the same issue. The problem with me was that there was a space on the file name, which didn’t sit well on iOS, so I replaced the space with a _

Related