File – Error code 5, encoding_err

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

My application uses ionic framework & ngCordova. I I want to save the image like this:

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));
});

When creating the file, this will give error code 5, ENCODING_ERR. Writing the file will not give a success or failure error. There is no image in the gallery. What should be the path to save the file? How should I send the image to the write method? Why do I receive an encoding error?

I encountered the same error and have found a solution. You may no longer need it , But someone is looking for it.

Add the following line to the configuration:



The file url is also It should start with file: ///...

I want to save the image from the ios application to the gallery so that users can share it.

< p>My application uses ionic framework & ngCordova. I want to save images like this:

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));
});

When creating the file, this will give error code 5, ENCODING_ERR. Writing a file will not give a success or failure error. There is no image in the gallery. What should be the path to save the file? How should I send the image to the write method? Why do I receive an encoding error?

I encountered the same error and have found a solution. You may no longer need it, but someone is looking for it.

Add the following line to the configuration:



File URL should also start with file: ///...

Leave a Comment

Your email address will not be published.