I'm trying to zip some sort of images.
const handleZip = async (e) => {
e.preventDefault();
const zip = new JSZip();
const folder = zip.folder(storeName);
for (let i = 0; i < QRCodes.length; i++) {
folder.file(`${i + 1}.jpg`, QRCodes[i]);
}
zip.generateAsync({ type: "blob" }).then((content) => {
FileSaver.saveAs(content, `${storeName}.zip`);
});
};
Result is StoreName.zip>StoreNameFolder>20 images formatted jpg
and these images are not working, it is corrupt. I also tried to change the image data with an image URL on the internet but the result was the same.
I've solved the issue with this;
const base64String = QRCodes[i].replace("data:", "").replace(/^.+,/, "");
folder.file(`${i + 1}.png`, base64String, { base64: true });