I have some URL of files. I want to download all the files as a zip file using JavaScript. Is there any easy way to do it?
Some files needs to be downloaded to create a zip file, which are those?
I have some URL of files. I want to download all the files as a zip file using JavaScript. Is there any easy way to do it?
Some files needs to be downloaded to create a zip file, which are those?
Share Improve this question asked Dec 28, 2017 at 10:39 UzmaUzma 211 silver badge1 bronze badge1 Answer
Reset to default 6This will get you started:
Download jsZip and load it in your html.
Then in your javascript:
var zip = new JSZip();
//skip this step if you don't want your files in a folder.
var folder = zip.folder("example");
folder.file("myfile1.txt", "HELLO WORLD IN 1ST FILE"); //requires filesaver.js
folder.file("myfile2.txt", "HELLO WORLD IN 2ND FILE");
//...so on until you have pleted adding files
zip.generateAsync({type:"blob"})
.then(function(content) {
//see FileSaver.js
saveAs(content, "example.zip");
});