Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading multiple files into a Zip file Javascript using data URI

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.

like image 343
Prateek Ratnaker Avatar asked Feb 23 '16 14:02

Prateek Ratnaker


1 Answers

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;
});
like image 99
André Bonna Avatar answered Sep 21 '22 03:09

André Bonna