I am using the javascript zip.js library. I've seach all around I a cannot find an example where more than one file is added to the zip.
Here is my code, but it generates a "corrupted" zip.
var len = results.rows.length, i;
var k=1;
zip.createWriter(new zip.BlobWriter(), function(writer) {
for (i = 0; i < len; i++){
// get the image url from a sqlite request
url = results.rows.item(i).url;
var img = new Image();
img.onload = function() {
var a = document.createElement('a');
a.href = this.src;
var filename= a.pathname.split('/').pop(); // filename.php
timest = new Date().getTime();
// use a TextReader to read the String to add
writer.add(timest+".jpg", new zip.Data64URIReader(getBase64Image(img)), function() {
// onsuccess callback
k++;
if(k==len){
setTimeout(function(){
writer.close(function(blob) {
// blob contains the zip file as a Blob object
$('#test').attr("href", window.URL.createObjectURL(blob));
$('#test').attr("download", "woeii.zip");
});
},1000);
}
}, function(currentIndex, totalIndex) {
// onprogress callback
});
};
img.src = url;
}
});
Any idea to make it work? :)