Page 1 of 1

Download all uploaded document with one click/button

Posted: Fri Jun 14, 2019 4:52 am
by Zora99
Can I download all the attachment files in dynaform only with one button/click?
Because sometimes my dynaform contains many uploaded documents and it's gonna be good for the user if they can download all of it at the same time instead of download the file one by one. Thankyou for your help.

Re: Download all uploaded document with one click/button

Posted: Fri Jun 14, 2019 4:58 pm
by amosbatto
There is no easy way to implement this.

You can download a single file in a MultipleFile field with this JavaScript:
$("#MultipleFileID").find("a.fa-download").aFiles.eq(X)[0].click();

Where MultipleFileID is the ID of the Multiple File field and X is the index number, such as 0, 1, 2, 3, etc.


However when I tried this code, I found that FireFox 60 and Chrome will only allow you to download one file and ignores the other download attempts. I tried this code:
Code: Select all
$("#downloadAll").find("button").click( function() {
  var aFiles = $("#specFiles").find("a.fa-download");
  var i = aFiles.length - 1;
  
  for (; i >= 0; i--) {
    aFiles.eq(i)[0].click();
  }
} );
I also tried using a settimeout() to download at different times, but I couldn't get it to work.

The only solution is to fire a trigger beforehand that queries the APP_DOCUMENT table in the database, and then uses exec("tar -cf files_case_X.tar file1 file2 file3") to create a tar file which contains all the files from the case. Then, use PMFAddInputDocument() or G::uploadFile() to add that tar file to the case. Then, display a link in the Dynaform to download that tar file.

Re: Download all uploaded document with one click/button

Posted: Wed Jun 19, 2019 5:08 am
by Zora99
Thank you very much Sir..