I used the following code but it is not working. I need help.
@yisrael-wix @J. D.
import JSZip from 'jszip';
import axios from 'axios';
import { saveAs } from 'file-saver';
$w.onReady(function () {
const zip = new JSZip();
const fileArr = [{
name: "file1.png",
url: "https://logos-download.com/wp-content/uploads/2016/05/Wix_com_logo_black.png",
},
{
name: "file2.png",
url: "https://logos-download.com/wp-content/uploads/2016/05/Wix_com_logo_black.png",
},
{
name: "file3.png",
url: "https://logos-download.com/wp-content/uploads/2016/05/Wix_com_logo_black.png",
},
];
const download = (item) => {
return axios.get(item.url, { responseType: "blob" }).then((resp) => {
zip.file(item.name, resp.data);
});
};
const downloadAll = () => {
const arrOfFiles = fileArr.map((item) => download(item));
Promise.all(arrOfFiles)
.then(() => {
zip.generateAsync({ type: "blob" }).then(function (blob) {
saveAs(blob, "hello.zip");
});
})
.catch((err) => {
console.log(err);
});
};
$w('#downloadBtn').onClick(() => {
downloadAll();
});
});