最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - download multiple files as zip - javascript - Stack Overflow

programmeradmin5浏览0评论

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 badge
Add a ment  | 

1 Answer 1

Reset to default 6

This 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");
      });
发布评论

评论列表(0)

  1. 暂无评论