Skip to content

Instantly share code, notes, and snippets.

@cici004
Created August 25, 2016 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cici004/20b998424eaa0ac6f0582dcab94ff819 to your computer and use it in GitHub Desktop.
Save cici004/20b998424eaa0ac6f0582dcab94ff819 to your computer and use it in GitHub Desktop.
doDownload : function() {
//TEST BEGIN to
var urls = [];
var rc = this.getRowsAndColumns();
console.dir(rc)
for (var i=0, il = rc.rows.length; i<il;i++){
var url = rc.rows[i].requ;
if(!urls.includes(url))
urls.push(url);
}
/*
for (var i=0, il = obj.length; i<il;i++){
var obj = resultmap[i].attributes.requ;
urls.push(obj);
}
*/
console.dir(urls)
var zip = new JSZip();
console.log("zip = "+zip);
var a = document.getElementById("downloadZipLink");
function request(url) {
return new Promise(function(resolve) {
var httpRequest = new XMLHttpRequest();
httpRequest.open("GET", url);
httpRequest.onload = function() {
zip.file(url, this.responseText);
resolve()
}
httpRequest.send()
})
}
Promise.all(urls.map(function(url) {
return request(url)
}))
.then(function() {
console.log(zip);
zip.generateAsync({
type: "blob"
})
.then(function(content) {
a.download = "folder" + new Date().getTime();
a.href = URL.createObjectURL(content);
a.innerHTML = "download " + a.download;
});
})
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment