Skip to content Skip to sidebar Skip to footer

Send Multiple Files To The User For Download One After Another

I'm trying to do the following: A grid with a lot of files is shown to the user The user selects as many files as he wants The user should be prompted for each file for the target

Solution 1:

I managed to build a possible example of downloading multiple files using the HTML FileSystem API. I ran into a few problems while building this which I'll note down below. Beware that this is just an example and could be improved by a lot (code-wise and feature-wise).

I stopped developing because I was unable to transfer binary files but maybe someone can give me a clue on how to do this. (I struggle with binary ajax transfers and JSON at the moment. (I can't say if it's possible to transfer images/binaries over ajax at all).

Published Sourcecode on GitHub:https://github.com/posixpascal/FileSystem-API-Example

A few things to note:

All I can say is that this is not a solution at the moment and the API isn't ready for the mass. You can add further support by using Flash and other utils to compensate lack of FileSystem API support.

How it works:

As soon as the user clicks on the download link, my script gathers information about the files using a server side PHP script. After that it requests a few chunks until the filesize from the locally stored file matches the one sent by the php script.

As soon as the file is ready, I create an invisible a tag and set href to "filesystem:myurl.de/theFile" and trigger a click event on that link. I also add 'download' property so the browser is forced to download .txt files as well.

This is not a fully solution to your problem but you can check the sourcecode and hopefully built something to suit your needs. I guess you already moved on to a different approach to download multiple files.

Solution 2:

I found a solution that works (for me) in all browsers. It's does not feel that good on the code side (at first) but it seems pretty stable to me on different browsers and different machines.

Chrome will ask the user to allow the site to download multiple files. IE doesn't care at all.

var onDownload = function(){
       var docs = module.getSelectedElements();        

       for(var i = 0; i < docs.length; i ++) {
           (function(){
               var doc = docs[i];
               window.setTimeout(function(){
                  $jq("#downloadIframe").attr("src", doc.url);
               }, i * 500);
           })();
       }

};

Post a Comment for "Send Multiple Files To The User For Download One After Another"