HTTP protocol was designed to send one file per one request.
Sometimes you will need to send more files - usually when a client selects several files for download and the files have to be delivered to the client.
I created ASP sample which will do such task - the sample is located at http://www.motobit.com/help.
Zip/Arj is great for download of files. But there are some tasks which require send more files in one request, for example HTML page with many small images as a preview.
Prepare multipart/related document
There are several steps to create and send multipart document from server. This sample is an ASP/VBS code, but you can simply create similar code for another environment.
Boundary is a unique string which separates file fields in multipart document. Encoded document files must not contain the string.
Mime header contains at least MIME-Version and Content-Type headers. The header has two CrLf at the end.
One file field consists from Boundary preceeded by two hypens ("--"). Next are multipart headers (Content-Type, Content-Location at least, you can add Content-Disposition, Content-ID, ...). Content-Location is a parameter for file location - SRC parameter of file, referred by first document.
I'm using base-64 encoding for binary files, but the encoding is not required.
First file in the multipart document should be main (start) HTML file, next fields are other data - images, scripts, etc.
The first file field contains HTML document. The document has standard formatting, including text, references, etc. There is a change in URL interpretting - local URLs (without http://) poinst to multipart document, to multipart fields, with Content-Location header as address. Next is a sample of the HTML - op.gif means multipart field with Content-Location: op.gif, A Href="cl.gif" means reference to cl.gif file field.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Tips</TITLE> <BASEFONT face="Arial, Verdana, Helvetica"> </HEAD> <Body TOPMARGIN=0 BGPROPERTIES=FIXED BGCOLOR=WHITE> <IMG src="op.gif" border=0> <br> <A Href="cl.gif"><IMG src="cl.gif" border=0></A> </BODY> </BASEFONT> </HTML>
Full source code of support functions.
There is an ASP file include _related.asp bellow,
containing support functions to send multipart data documents.
First sample sends an HTML formatted file (img/primary.htm) along with two images. The files are located in img/ relative folder.
Next sample is a complette list of images in one folder. The images are send as a preview in one response stream to a client.
for 'Download multiple files in one http request' articleWork with binary files in VBSscript - read and write local and remote filesReading and writting binary and text files is a first task you will need to solve in server-side ASP. This article contains several VBS functions which let's you store data to local disk and read local or remote (http) files.
Automatic file upload using IE+ADO without user interaction - VBSscriptLets you upload file from a client to www server over http connection using vbs, IE and ADODB. The file is sent as a result of type=file form field encoded multipart/form-data.
Copyright and use this code
The source code on this page and other samples at http://www.motobit.com/tips/ are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
2. Link this sample from you page.
<A Href="http://www.motobit.com/tips/detpg_multiple-files-one-request/" Title="This article shows a way to download multiple files in one http request. It let's you send an HTML page along with image preview, prepare more files for download and send the files as one data stream. One request, one authentication per multiple files." >Download multiple files in one http request</A>
© 1996 - 2013 Antonin Foller (Google Plus), Motobit Software | About, Contacts | (Find us on Google+)
Partner sites: Search Czech Last minute Zajezdy Obsah na mobil Hry na mobil Java Hry Print-shop Affiliate programy
|IISTracer - IIS ISAPI real-time monitor IISTracer is a real-time monitoring tool for Microsoft IIS, which will show/log you what is happenning on IIS server right now. It let's you reveal problems with long-running scripts (.asp, .cgi, cfm...), hang-up states and low resource situations and lets you stop long-running requests (uploads/downloads).||ActiveX User account Manager - Set of simple objects for creating, deleting, and managing user accounts, groups, servers and domains in the Windows NT environment.|
|Active log file - Hi-performance text file logging for ASP/VBS/VBA applications. Lets you create daily/weekly/monthly log files with variable number of logged values and extra timing and performance info.||ActiveX windows registry editor - Intuitive, easy to use COM interface to windows registry. Set of classes to read/enumerate/modify windows registry keys and values from ASP, VBS and T-SQL.|
|ActiveX/ASP Multi Dictionary object - Free-threaded hi-speed dictionary algorithm with unique/nonunique keys (map/multimap). Connect to another dictionary object in the same process. Lock and Unlock methods to synchronize tasks (application scope). Share ASP Application/Session objects.||Export DBF/MDB from ASP - Conversion from recordset to MDB/DBF. Direct binary output of MDB or DBF files from ASP pages with one row of code.|
|Pure-ASP upload - lets you upload files using Pure ASP VBS code (using multipart/form-data and input type=file).||ByteArray - Works with safearray binary data (VT_UI1 | VT_ARRAY) - save/restore binary data from disk, find, work with code pages, convert to string/hexstring(SQL).|
|WebChecker - Checks http, https, ftp and gopher internet connections in regular intervals. Lets you monitor web site functionality (uptime). Enables restart or notification on problems.||HTTPLog ISAPI filter - Lets you log incomming/outgoing http header and document data to separate files. Monitor of IIS service input/output.|