Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
jquery fileDownload: download multiple files into chunks

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?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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);
      }
    );
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!