views:

543

answers:

5

I would like to open multiple download dialog boxes after the user clicks on a link.

Essentially what I am trying to do is allow the user to download multiple files. I don't want to zip up the files and deliver one zipped file because that would require a lot of server resources given that some of the files are some what large.

My guess is that there may be some way with javascript to kick off multiple requests when the user clicks on a certain link. Or maybe there might be a way on the server side to start off another request.

+3  A: 

Unless the client is configured to automatically download files, you can't accomplish this without packaging the files in a single response (like ZIP solution you mentioned.) This would be a security issue if a Web site would be able to put arbitrarily large number of files on your disk without telling you.

By the way, you might be overestimating the cost of packaging in a single file. Streaming files is usually an I/O-bound operation. There should be enough CPU cycles to spare for piping the data through some storage(tar)/compression(zip) methods.

Mehrdad Afshari
+2  A: 

If you absolutely, positively cannot zip at the server level, this would probably be a good instance for creating some sort of custom "download manager" client-side plugin that you would have the user install and then you could have complete control over how many files you downloaded, where they went, etc.

MattC
+2  A: 

I suppose you could link to a frameset document or a document containing iframes. Set the src of each from to one of the files you want to download.

That said, a zipped version would be better. If you are concerned about the load then either:

  • zip the files with compression set to none
  • use caching on the server so you zip each group of files only once
David Dorward
A: 
  1. Present a page with a form of check boxes of the available files for download - with multiple select enabled for the check boxes.
  2. User selects multiple files and submits forms.
  3. Server accepts request and creates a page with serial-triggered file download javascript.
  4. The page with the embedded javascript is presented to the user's browser, listing and asking for confirmation the files to be serially downloaded.
  5. User clicks [yes - serially swamp my harddisk with these files] button.
  6. foreach file, listener for download completed triggers the next download, until end of list.

I only know how to do this using Google GWT, where I had set up GWT RPC between browser and server. Took me two weeks to understand GWT RPC and perfect the download. Now it seems rather simple.

Basically (do you know basically is one of the most used non-technical words among the geek community?), you have to declare a server service class specifying the datatype/class of transfer. Where the datatype must implement serializable. Then on the browser-side the GWT client declares a corresponding receiver class specifying the same serializable datatype. The browser side implements a listener for onSuccess and onFailure.

Hey, I even managed to augment GWT service base class so that I could use JSP rather than plain servlets to implement the service interface.

Actually, I was not downloading a series of files but streams that conditionally serially triggered the next stream, because my onSuccess routine would inspect the current stream to decide what content to request for on the next stream.

Ok, two weeks was an exageration, it took me a week to do it. A genius would have taken half a day only.

Blessed Geek
A: 

I vote for the GWT implementation of file downloading. Did u do the file downloading via one RPC call or you actually slice the file into pieces?

Frank