I am currently developing an Angular2 v4 app using Typescript and I'm looking for a solution to download multiple images (in base64 format) as a Zip file.
For instance, I have a sample array like this (containing fake base64 images just for illustration purposes)
data = [
'data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUA ...',
'data:image/png;base64, iVBTYu0KGgoBBBBNSUhYUgJJJJUA ...',
'data:image/png;base64, CGBHHFGY0goAAAANSUhEUgAAAAUA ...',
...
]
I require a method to download these images by first converting each one to a .jpg or .png file, then compiling all the images and downloading them as a zip file. The concept is demonstrated below:
downloadZip() {
const arrayAsJPG = [];
this.data.forEach(i => {
const imageInJpg = i.convertToJPGfile(); // This function converts base64 to JPG file
arrayAsJPG.push(imageInJpg);
});
ZipFileSaver.save(arrayAsJPG, 'myImageReport.zip'); // This is a conceptual representation of what I need
}
Is there a way to achieve this task efficiently?