Zip Upload

JFile allows you to zip files before uploading them to the server, or extract files from a downloaded zip file.

Zipping files before transfer can increase the speed of a multi-file upload. However, as zipping the files takes time, it may not improve performance in the case of small transfers.

Use the ZipFiles parameter to zip files before upload. When ZipFiles is set to a value other than 0, JFile will zip the files to upload, and transfer a zip file to the server. Files may be either compressed in the zip or simply stored, depending on the value of the ZipMethod parameter.

ZipMethod takes one of two parameters:

Zip Upload Status Dialog

While zipping files before an upload, JFile displays a status window. The window contains a message and a Cancel button. By default, the message displayed is Preparing Upload. To change the status message, set LabelZipStatus. Clicking the Cancel button aborts the transfer. To change the text on the Cancel button set LabelCancelButton.

File Naming in Zip Uploads

If ZipMethod is set to "deflated," and a file is selected directly (rather than through a directory upload), it will be stored in the zip file with its original name, and without path information. If several files with the same name are added to the zip, "_(number)" will be appended to all but the first file name (for example, file.txt, file_(1).txt, file_(2).txt).

If ZipMethod is set to "stored," and a file is selected directly (rather than through a directory upload), it will be stored in the zip file with its original name and path information.

In the case of directory uploads (recursive or not), files will be added to the zip with their original names and relative paths. If several folders with the same name are added to the zip, "_(number)" will be appended to all but the first folder name (for example, a zip could contain folder\file.ext, folder_(1)\file.ext, and folder_(2)\file.ext).

Exercise 8: Zip Upload

  1. If you created the physical and virtual JFileScripts directories in a previous lesson, go to Step 4. If you did not create the directories, go to Step 2.

  2. Create a directory called JFileScripts and copy the file formresp.asp to this directory. Formresp.asp is a server-side upload processing script that you will find in JFile's Samples\Upload\Simple directory (installed by default at C:\Program Files\SoftArtisans\JFile). Formresp.asp uses SoftArtisans FileUp to process the upload.

  3. Copy filetransfer.jar (for Netscape) and/or filetransfer.cab (for Internet Explorer) to the directory JFileScripts. These files are in JFile's installation directory (by default, C:\Program Files\SoftArtisans\JFile).

  4. Open formresp.asp and replace upl.Form(item).SaveAs filename with upl.Form(item).SaveAs "sample.zip". Save formresp.asp as formrespzip.asp.

  5. Create a virtual directory called JFileScripts and map it to the physical JFileScripts you created in step 1:

    1. Open the Internet Information Services (IIS) explorer.
    2. Right-click Default Web Site.
    3. Select New -> Virtual Directory.
    4. For Alias, enter JFileScripts.
    5. Browse to the JFileScripts directory you created in step 1.
    6. Check "Read" and "Run scripts."
    7. Click "Finish."

  6. Create an HTML script containing the following lines. Name the script zipupload.htm and save it in your JFileScripts directory.
    <APPLET codebase="/JFileScripts" code="softartisans.filetransfer.UploadClient.class" 
    height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload">
    	
    	<!-- The Cabbase parameter specifies the cab file containing the applet. -->
    	<PARAM name="cabbase" value="filetransfer.cab">
    
    	<!-- The PostURL parameter specifies the URL to which the file will be posted. -->
    	<PARAM name="PostURL" value="http://localhost/jfilescripts/formresp.asp">
    	
    	<!-- The FileName# parameter specifies a file to transfer.  When uploading more than one file, use 
    	"FileName1," "FileName2," etc. -->
    	<PARAM name="FileName1" value="c:\autoexec.bat">
    	<PARAM name="FileName1" value="c:\config.sys">
    	
    	<!-- When ZipFiles is set to a value other than 0, JFile will zip the files 
    	to upload, and transfer a zip file to the server. -->
    	<PARAM name="ZipFiles" value="1">
    	
    	<!-- By default, the value of ZipMethod is "deflated" and files 
    	will be compressed in the zip.  To store without compressing, set 
    	ZipMethod to "stored" as follows.
    	<PARAM name="ZipMethod" value="stored">  -->
    	
    	<!-- To change the message displayed in the zip status window, set 
    	LabelZipStatus -->
    	<param name="LabelZipStatus" value="Zipping Files">
    	
    	<!-- The zip status window contains a Cancel button.  Clicking this button 
    	aborts the transfer.  To change the button's text set LabelZipCancelButton -->
    	<param name="LabelZipCancelButton" value="Cancel Transfer">
    	
    </APPLET>
  7. To run the script, open the browser, and enter the URL http://localhost/jfilescripts/zipupload.htm.

Understanding the Script