Save data string image to gallery in cordova app


#1

Hi Guys…
I just try to save the data string(data:image/png;base64) formated.But i get an error says “Error while saving image” .This the callback error from window.imageSaver.saveBase64Image();
here is the my code

var params = {data: base64Data, prefix: 'coupon_', format: 'JPG', quality: 80, mediaScanner: true};
         window.imageSaver.saveBase64Image(params,
            function (filePath) {
              console.log('File saved on ' + filePath);
            },
            function (msg) {
              console.error(msg);
            }
          );

Im also tried this too.But shows the same error “Error while saving image”

cordova.base64ToGallery(
        base64Data,
 
        {
            prefix: 'img_',
            mediaScanner: true
        },
 
        function(path) {
            console.log(path);
        },
 
        function(err) {
            console.error(err);
        }
    );

What does this error means? Anybody can help me?


#2

Why aren’t you using ionic-native here?


#3

How can we save the base64 image into the gallery while using ionic-native file transfer ?


#4

Having the same problem.Did you find the solution?


#5

Yes, Here is my code
/-------
var fileTransfer = new FileTransfer();
var uri = encodeURI($scope.ImgSrc);
if(device.platform==‘iOS’){
var storeDirectory = cordova.file.syncedDataDirectory;
}else{
var storeDirectory = cordova.file.externalApplicationStorageDirectory;
}
fileTransfer.download(
uri,
storeDirectory+‘something.png’,
function(entry) {
cordova.plugins.imagesaver.saveImageToGallery(entry.toURL(), function(successCallback){
}, function(errorCallback){
});
},
function(error) {
console.log("download error source " + error.source);
console.log("download error target " + error.target);
console.log(“download error code” + error.code);
},
false,
{
headers: {
“Authorization”: “Basic ‘authKey’”
}
}
);

   -----/