Попробуйте этот код ниже.Это позволит загрузить и сохранить изображение в папке приложения и отобразить в галерее.
downloadImage(fileName, ext, base64) {
let storageDirectory: string = "";
//Select Storage Location
if (this.platform.is('ios')) {
storageDirectory = cordova.file.documentsDirectory + '<Your Folder Name>/';
}
else if (this.platform.is('android')) {
storageDirectory = cordova.file.externalDataDirectory + '<Your folder name>/';
}
else {
return false;
}
//Request Access
if (this.platform.is("android")) {
this.diagnostic.requestRuntimePermission('READ_EXTERNAL_STORAGE').then(() => {
console.log("Success");
})
}
//Download Image
var uri = encodeURI('data:' + "image/png" + ';base64,' + base64);
var fileURL = storageDirectory + "Image.png".replace(/ /g, '%20');
this.fileTransfer.download(uri, fileURL).then((success) => {
base64 = 'data:' + "image/png" + ';base64,' + base64;
const alertSuccess = this.alertCtrl.create({
title: `Download Succeeded!`,
subTitle: `Image was successfully downloaded`,
buttons: ['Ok']
});
alertSuccess.present();
}, error => {
const alertFailure = this.alertCtrl.create({
title: `Download Failed!`,
subTitle: `Image was not successfully downloaded. Error code: ${error.code}`,
buttons: ['Ok']
});
alertFailure.present();
})
}