Upload multiple files to a Javascript zip file using data URI

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

When you click on it, several (six) files are downloaded. I want these files to be loaded into a single ZIP file.

+4
source share
1 answer

There is an ideal plugin for creating ZIP files inside the browser.

JSZip: https://stuk.imtqy.com/jszip/

Install the plugin by adding js files manually:

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

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;
});
+3

Source: https://habr.com/ru/post/1630073/


All Articles