Simultaneous Downloading of Multiple Files

At some point, you may need to download multiple files at the same time. This example shows how to download multiple files simultaneously using both SA-XFile and SA-JFile. Both samples use the same method of downloading files and the response page for SA-FileUp.

Using SA-XFile

This first example illustrates using SA-XFile's ActiveX control. You'll find this useful in getting around browsers' usual limitation of downloading one file at a time.

For this example, we need two HTML files (SAXFileMultiDown.htm and AXFFileProgress.htm) and one ASP file - FormResp.asp. The first HTML file will contain our ActiveX control interface, with which the user selects one or all the files to be downloaded. The other one allows us to view the progress of the download. The ASP file, named FormResp.asp, is where SA-FileUp will take the request for the download and transfer the files from the server to the browser.

<%@ LANGUAGE="VBSCRIPT" %>


<HTML>
<HEAD>
<TITLE>Software Artisans SA-AXFile Download Sample</TITLE>
<%
'--- Server name 
httpHost = "localhost"

'--- Files to be downloaded
File1 = Server.URLEncode("boot.ini")
File2 = Server.URLEncode("config.sys")

%>
</HEAD>
<BODY>
<P><STRONG><FONT color=black size=5>SA-AXFile Download Sample</FONT></STRONG></P>
<P>
<SCRIPT>

Function StartDownload() {
	WinStyle="Height=300,Width=400,Status=No,Toolbar=To,Menubar=No,Location=No";
	Window.Open("AXFFileProgress.htm",Null,WinStyle);
}

</SCRIPT>

<OBJECT ClassID=CLSID:B82FA17C-F3A9-11D2-B5DD-0050041B7FF6 Height=200 
ID=AXFFileDownload Style="HEIGHT: 200px; LEFT: 0px; TOP: 0px; WIDTH: 400px" 
Width=400 VIEWASTEXT>
</OBJECT>
</P>
<P><INPUT ID=Button1 Name=Button1 Type=Button Value="Start Download" OnClick = "StartDownload()"></P>

<Script Language="vbs">
    Set XFile = AXFFileDownload.XFRequest 
      
    XFile.Server = <%=httpHost%>
    
    AXFFileDownload.AddFile "c:\temp\boot.ini", _
    "http://localhost/SAFileUpSamples/ClientDownload/MultiDownload/FormResp.asp?File=" _
    & "<%=File1%>"
    
    AXFFileDownload.AddFile "c:\temp\config.sys", _
    "http://localhost/SAFileUpSamples/ClientDownload/MultiDownload/FormResp.asp?File=" _
    & "<%=File2%>"
	
</script>

</BODY>
</HTML>

That's obviously a lot of information to take in at once so we'll cover the code one section at a time:

AXFFileProgress.htm is a much simpler file, but the most important. This page starts the download process. We are calling the SA-XFile's Progress object, in order to display the status of the transfer. We ensure that the progress control is displayed before the transfer starts. Otherwise, in the multi-threaded environment of Internet Explorer, a transfer could complete before the progress window is displayed, yielding an inconsistent user experience.

<HTML>
<HEAD>
<TITLE>Software Artisans SA-AXFile Download Progress</TITLE>

<SCRIPT>
Function Callback()
{
	Document.All["AXFFileProgress"].XFRequestStream =  Opener.Document.All["AXFFileDownload"].XFRequestStream;
	Document.All["AXFFileProgress"].ShowProgress();
	Opener.Document.All["AXFFileDownload"].Start();
	window.close()
}

</SCRIPT>
</HEAD>
<BODY OnLoad="Callback()">
<OBJECT ID="AXFFileProgress" CLASSID="CLSID:C3EAF164-E06A-11D2-B5C9-0050041B7FF6"></OBJECT>
</BODY>
</HTML>

The sections of this file work as follows:

The last page deals with the download via the server. This is where SA-FileUp is used to direct where the source file is on the server. This has very little code, but you can imagine adding more sophisticated functions for authorizations, loggin, and management of the download.

There is the major section:

<%

'--- get the QueryString value to be used as the source file to be downloaded.
File = Request.QueryString("File") 

'---
'--- Instanciate the file download component
'---
Set download = Server.CreateObject("SoftArtisans.FileUp")


'--- The root path would be supplied for the source of the download. 
'--- In this example it is hard coded.
download.TransferFile "C:\" & File

%>

SA-FileUp requires only a single parameter: the full path of the file to be transferred to the server. In this example, both files are in the same folder. You could also use the Querystring to specify an ID or some other means of making the server filename hidden.
If the download is complete, you will see checkmark over files inside of the interface. You could also use the transfer complete method with in the AXFFileProgress.htm for additional user interaction.

Using SA-JFile

With SA-JFile, we need to use Querystring in order to supply the file name through out. This also makes it easy to use one response page to implement the download of all of your files.

Here is the code for the first page:

<%@ LANGUAGE="VBSCRIPT" %>
<%
	

	httpHost = Request.ServerVariables("HTTP_HOST") 

	' This is the final URL where the applet will invoke after all files have been downloaded
	' to confirm to the server that the files were successfully downloaded
	FinalURL = "http://" & httpHost & "/SAFileUpSamples/ClientDownload/MultiDownload/SAJFile/confirm.asp"
	
	' This will tell the applet where to place the file on the user's system
	Folder = "c:\temp\"
	
	'--- This defines how the download is done with SA-FileUp.
	Session("File1") = "boot.ini"
	Filename1 = Folder & Session("File1")
	URL1 = "http://" & httpHost & _ 
	"/SAFileUpSamples/ClientDownload/MultiDownload/FormResp.asp?File=" & Session("File1")
	
	Session("File2") = "config.sys"
	Filename2 = Folder & Session("File2")
	URL2 = "http://" & httpHost & _ 
	"/SAFileUpSamples/ClientDownload/MultiDownload/FormResp.asp?File=" & Session("File2")
	
%>

<HTML>
<HEAD>
<TITLE>
	SA-JFile Multiple File Download
</TITLE>
</HEAD>

<BODY>

<CENTER><H2>SA-JFile Multiple File Download</H2></CENTER>
<br>
<P>
	In this example, we will download two files into one directory. Query strings are used to
	to transfer the name of the file for the destination and the source file.
</P>
<br>

	<APPLET codebase="/SAJFilesamples" code="softartisans.filetransfer.DownloadClient.class" height="0" width="0" mayscript archive="filetransfer.jar" name="filedownload" VIEWASTEXT>
		
		<PARAM name="cabbase" value="filetransfer.cab">
		<PARAM name="FinalURL" value="<%=FinalURL%>">
		<PARAM name="Filename1" value="<%=Filename1%>">
		<PARAM name="URL1" value="<%=URL1%>">
		<PARAM name="Filename2" value="<%=Filename2%>">
		<PARAM name="URL2" value="<%=URL2%>">
	</APPLET>
</BODY>
</HTML>

Here are some major points:

The next page is where the download process actully takes place, using SA-FileUp. This is the same formresp.asp we used in the SA-XFile example.

<%@ LANGUAGE="VBSCRIPT" %>

<%

File = Request.QueryString("File") 

'---
'--- Create an instance of the file download component
'---
Set download = Server.CreateObject("SoftArtisans.FileUp")

'--- The root path would be supplied for the source of the download. In this example it is hard coded.
download.TransferFile "C:\" & File

%>

The last page is displayed if the download was successful.

<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>
	Software Artisans Java Multiple File Download Sample
</TITLE>
</HEAD>

<BODY>

<CENTER><H2>SA-JFile Mulitple Download Sample</H2><CENTER>
<br>
Thank you for downloading the files  
<%Response.Write Session("File1") & " and " & Session("File2")%>.

</BODY>
</HTML>

This page includes the Session variables that were created on the first page.

For more examples, check out the samples provided as part of the SA-FileUp distribution. See Programmer's Samples for a list of the contents of the Samples directory.

 

Previous Page Next Page