Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download multiple files with one HTTP request?

Use case: user clicks the link on a webpage - boom! load of files sitting in his folder.
I tried to pack files using multipart/mixed message, but it seems to work only for Firefox

This is how my response looks like:

HTTP/1.0 200 OK Connection: close Date: Wed, 24 Jun 2009 23:41:40 GMT Content-Type: multipart/mixed;boundary=AMZ90RFX875LKMFasdf09DDFF3 Client-Date: Wed, 24 Jun 2009 23:41:40 GMT Client-Peer: 127.0.0.1:3000 Client-Response-Num: 1 MIME-Version: 1.0 Status: 200  --AMZ90RFX875LKMFasdf09DDFF3  Content-type: image/jpeg  Content-transfer-encoding: binary  Content-disposition: attachment; filename="001.jpg"   << here goes binary data >>--AMZ90RFX875LKMFasdf09DDFF3  Content-type: image/jpeg  Content-transfer-encoding: binary  Content-disposition: attachment; filename="002.jpg"   << here goes binary data >>--AMZ90RFX875LKMFasdf09DDFF3  --AMZ90RFX875LKMFasdf09DDFF3-- 

Thank you

P.S. No, zipping files is not an option

like image 977
zakovyrya Avatar asked Jun 24 '09 23:06

zakovyrya


People also ask

Is there a way to download multiple files at once?

Hold CTRL and click on the files you want to download. Once you have selected the files you want, right click on the last file you selected and select download.


1 Answers

Zipping is the only option that will have consistent result on all browsers. If it's not an option because you don't know zips can be generated dynamically, well, they can. If it's not an option because you have a grudge against zip files, well..

MIME/multipart is for email messages and/or POST transmission to the HTTP server. It was never intended to be received and parsed on the client side of a HTTP transaction. Some browsers do implement it, some others don't.

As another alternative, you could have a JavaScript script opening windows downloading the individual files. Or a Java Applet (requires Java Runtimes on the machines, if it's an enterprise application, that shouldn't be a problem [as the NetAdmin can deploy it on the workstations]) that would download the files in a directory of the user's choice.

like image 85
Andrew Moore Avatar answered Oct 12 '22 01:10

Andrew Moore