Downloading multiple files into a Zip file Javascript using data URI

拥有回忆 提交于 2019-12-12 11:34:42

问题


I am using EXT JS 4.2 which has a panel which contains a export to CSV button.

On clicking on it multiple (total six) files are downloaded. I want these files to be downloaded in a single ZIP file.


回答1:


There is a perfect plugin to create zip files inside browser.

JSZip: https://stuk.github.io/jszip/

Install the plugin by adding js files manually:

download JSZip and include the file dist/jszip.js or dist/jszip.min.js

JSFiddle - JSZip 3.0:

https://jsfiddle.net/andrebonna/u8zsbzau/

var zip = new JSZip();
for (var i = 0; i < 5; i++) {
    var CSV = 'CSV_content';
    // Fill CSV variable
    zip.file("file" + i + ".csv", CSV);
}

zip.generateAsync({
    type: "base64"
}).then(function(content) {
    window.location.href = "data:application/zip;base64," + content;
});


来源:https://stackoverflow.com/questions/35579820/downloading-multiple-files-into-a-zip-file-javascript-using-data-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!