Error code 5, ENCODING_ERR when saving an image from the application directory in the phone’s image gallery

I want to save the image from the ios app to the image gallery so that the user can share it.

My application uses ionic structure and ngCordova. I am trying to save the image as follows:

image = cordova.file.applicationDirectory + "www/img/deck/" + card.image; file_path = cordova.file.documentsDirectory + "wisdom.png"; $cordovaFile.createFile(file_path, true).then(function(result) { alert(JSON.stringify(result)); }, function(err) { alert('create error: ' + JSON.stringify(err)); }); $cordovaFile.writeFile(file_path, image).then(function(result) { alert(JSON.stringify(result)); }, function(error) { alert(JSON.stringify(err)); }); 

This gives error code 5, ENCODING_ERR - when creating the file. Record file does not give success or error with error. There is no image in the gallery. What should be the path to save the file? How to send image to recording method? Why am I getting a coding error?

+5
source share
1 answer

I encountered the same error and already found a workaround for it. You may not need this, but someone is looking for it.

Add these lines to your config:

 <preference name="iosPersistentFileLocation" value="Library" /> <preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" /> 

Also, the url file should start with the file: /// ...

0
source

Source: https://habr.com/ru/post/1210018/


All Articles