I'm using https://github.com/johnculviner/jquery.fileDownload to download an array of files. It seems working:
for (var index = 0; index < files.length; ++index) {
var file = files[index];
$.fileDownload(file)
.done(function() {
alert("Done " + file);
}
)
.fail(function() {
alert("Fail " + file);
}
);
}
How can I download the files in chunks of 5 files at a time? The files are downloading, but no alert is showing for the moment. So I think maybe I have a problem here.
When trying to download 100 files, for example, I want to download 5, then other 5 etc until done for all. Is this possible?
Download first file
var firstfile = files[0]; //first file id
var downloadresult = downloadFileEx(firstfile);
Then chain other files with jquery then and use array.slice to pick the chunk
var begin=1; // start from second file
var end=5;
do {
for (var index = begin; index < files.slice(begin, end).length; i++) {
var file = files[index];
(function (index) {
downloadresult = downloadresult.then(function() {
return downloadFileEx(array[index]);
});
}(index));
}
index++;
}
begin = begin +5;
end = end + 5;
}
while (end < files.length);
write the file download functiom
function downloadFileEx(file) {
return $.fileDownload(file)
.done(function() {
alert("Done " + file); // remove this 100 alerts will be blocked by browser, maintain an array of files
}
)
.fail(function() {
alert("Fail " + file);
}
);
}