XUpload 1.0 Manual

http://www.aspupload.com/xupload.html

Copyright (c) 1999 Persits Software, Inc.
All Rights Reserved.
 

IMPORTANT NOTICE: Information contained in this document is preliminary. Certain features may be changed or removed from  the final release of XUpload, and new features may be added. Please read the Disclaimer for important warranty information. For suggestions and comments, please write to info@aspupload.com.

What is XUpload?

XUpload 1.0 is a client-side ActiveX control for uploading files from a user's machine to the Web server using the RFC1867 standard. The purpose of XUpload is to overcome numerous limitations of purely browser-based upload solutions. With XUpload, users can upload files to the server from a web page viewed by Microsoft Internet Explorer, from a custom application built with Visual Basic, Visual C++ or any other platform supporting ActiveX, or directly from File Explorer (see section Using XUpload as a Shell Extension.)

To upload files to the server, XUpload needs to invoke a server-side upload component such as AspUpload from Persits Software, Inc. All the samples in this manual assume that your web server has this component installed. A free trial copy of the AspUpload component can be downloaded from http://www.aspupload.com.

The XUpload 1.0 control used the Microsoft Internet Explorer 4.0 WinInet API. Therefore, XUpload requires that Microsoft Internet Explorer 4.0+ be installed, even if the control is used in containers other than IE.
 

Limitations of Form-based Uploading

RFC1867-compliant browsers such as IE 4.0+ or Netscape 3.0+ perform file uploads using an HTML form with the attributes <FORM METHOD="POST" ENCTYPE="multipart/form-data">. This form must contain one or more items of the type <INPUT TYPE=FILE>. The browsers display such items as regular text boxes with the button "Browse..." next to them. Clicking the Browse button invokes the standard Choose File dialog box which allows the user to select a file for uploading. The limitations of form-based uploading are these: This manual demonstrates how you can overcome all these limitations with the help of the XUpload control.

Getting Ready

Create the virtual directory XUpload with the Execute permission on top of your XUpload installation directory and make sure your Web server is running. You must also have the AspUpload component  installed and registered on your machine. This upload component can be downloaded from www.aspupload.com.

Using XUpload with Internet Explorer

When used with IE, the XUpload control runs inside an HTML page on a client machine. The HTML page must reference the control using the <OBJECT> tag, as follows:

<OBJECT WIDTH=500 HEIGHT=200
 ID="UploadCtl" CLASSID="CLSID:E87F6C8E-16C0-11D3-BEF7-009027438003" CODEBASE="XUpload.ocx">
...
</OBJECT>

Generally, XUpload does not need to be registered on the Web server (because it runs on the client machine) but it does not need to be placed in a virtual directory together with HTML pages it is referenced by so that the browser, after coming across the <OBJECT> tag, can download the XUpload.ocx file to the client machine and register it there.

The WIDTH and HEIGHT attributes of the <OBJECT> tag define the size of the control inside the page. The ID attribute identifies the XUpload object so that it can be used by client-side VB Script. The CLASSID attribute specifies the XUpload control's globally unique identifier (GUID) which the browser uses to create an instance of the control.  The CODEBASE attribute specifies where the file XUpload.ocx resides relative to the current HTML page.

Fire up your browser and open the URL http://127.0.0.1/XUpload/Simple.htm. Unless XUpload.ocx was previously registered on your machine, you should see a dialog box similar to this one:


 

The file XUpload.ocx was digitally signed to provide proof to the user that the control he is about to install on his machine really came from Persits Software, Inc., and that it was not tempered with during transmission. Click "Yes" to have the browser install the control on your computer.

You should now be able to see the control inside your browser. It looks like a regular Win32 list control with two columns, Files and Size. Right-click anywhere inside the control. A pop-up menu appears with three menu items, "Select", "Remove All" and "Upload".

The Remove All and Upload items are grayed out as there is no files selected. Choose Select to invoke the standard "Select Files" dialog box. Choose a few files and click Ok. The selected files appear in XUpload's list control with their respective icons and size information. We can now remove any or all files from the list by highlighting the appropriate items, right-clicking inside the control and choosing Remove or Remove All. We can also sort the items alphabetically or by size by clicking on the Files or Size headers, respectively.

However, if we attempt to choose "Upload", the control reports the error "Server Not Specified." This is because the file Simple.htm only creates the control but does not configure it to do any useful job.

At the very minimum, you must supply values for two XUpload properties: Server and Script. The Server property specifies the address of a destination web server, such as "www.persits.com" or "192.168.112.221". The Script property is the path to an upload script on that server, such as "/upload/myuploadscript.asp". These two properties together serve the same purpose as the ACTION attribute of an HTML POST form.

The properties of an ActiveX control can be specified using <PARAM> tags placed between the <OBJECT ...> and </OBJECT> tags. Open the file Simple.htm in a text editor and insert the following lines:

<OBJECT WIDTH=500 HEIGHT=200
 ID="UploadCtl" CLASSID="CLSID:E87F6C8E-16C0-11D3-BEF7-009027438003" CODEBASE="XUpload.ocx">
<PARAM NAME="Server" VALUE="127.0.0.1">
<PARAM NAME="Script" VALUE="/xupload/uploadscript.asp">
</OBJECT>

Here we use the upload script UploadScript.asp included with the XUpload control. This script saves uploaded files in the "c:\Upload" directory, so you should make sure this directory exists or edit the script to specify a different directory.

We can go back to the browser and hit Refresh so that the newly entered <PARAM> tags can take effect. All the selected files disappear as the browser creates a new instance of the control. Select a few files again and choose "Upload". A dialog box with two progress bars appears so that you can watch the progress of your upload. Once the uploading is complete, a message box titled "Reply from Server" pops up:

The text inside the message box came directly from the server and was generated by the upload script. It is therefore important to keep upload scripts used by XUpload free of HTML tags and reduce the output they generate to a minimum.

XUpload can be configured not to display the Reply from Server message box by setting the ViewServerReply property to False as follows:

<PARAM NAME="ViewServerReply" VALUE="False">

If you choose to do so your application may need to provide some other means to report server replies to the user, such as handling the ServerReply event (see section Handling Events.)

Configuring Select Files for Uploading Dialog

An important advantage of XUpload over a purely browser-based solution is being able to specify the "Select Files" dialog's default directory and file filters. The corresponding properties are Directory and Filter. The usage of the Directory property is straightforward:

<PARAM NAME="Directory" VALUE="c:\My Documents\Spreadsheets">

The Filter property accepts a list of pairs separated by the pipe character ( | ). Each pair defines a verbal description for a filter and the filter itself which may contain one or more wildcards separated by a semicolon (;). The two values in the pair are also separated by the pipe character. For example,

<PARAM NAME="Filter" VALUE="Images (.gif;.jpg)|*.gif;*.jpg|Documents (.doc)|*.doc|All Files|*.*">

Here we specify three filters. The first filter has the verbal description "Images (.gif;.jpg)" and consists of two wildcards, *.gif and *.jpg. The second filter has the description "Documents (.doc)" and is defined by the wildcard *.doc. The third filter is "All Files" with the wildcard *.*.

Setting Limits on Files Being Uploaded

XUpload enables you to impose certain restrictions on the files being uploaded, so that the files not meeting the restrictions are rejected before an upload begins. The restrictions are set via the propteries MaxFileCount, MaxFileSize, MaxTotalSize and Extensions. The MaxFileCount property, if set to a non-zero value, limits the total number of files selected for uploading. The MaxFileSize property, if set to a non-zero value, places a limit on the size of individual files (in bytes). The MaxTotalSize property, if set to a non-zero value, sets a limit on the total size of files selected for uploading (in bytes). These three properties are 0 by default. The Extensions property can be used to specify a list of acceptable file extensions. For example,

<PARAM NAME="MaxFileSize" VALUE="50000">
<PARAM NAME="MaxTotalSize" VALUE="200000">
<PARAM NAME="MaxFileCount" VALUE="10">
<PARAM NAME="Extensions" VALUE="gif,doc,jpg">

The Extensions restriction is enforced at the time of adding a file to the list. The other three restrictions are enforced at the time when XUpload is instructed to start an upload (via the user interface or Upload method.) An attempt to upload a set of files not meeting the MaxXXX restrictions results in an error message being displayed by the control.

Populating File List with Default Values

XUpload can be configured to populate its file list automatically upon loading. This is done via tags of the form <PARAM NAME="FileN"> where N is a number greater than 0. When XUpload loads it attempts to retrieve the PARAMs File1, File2, File3, etc. until a break in the sequence is encountered, and uses the corresponding values to populate its file list. For example,

<PARAM NAME="File1" VALUE="c:\My Documents\Spreadsheets\Bool1.xls">
<PARAM NAME="File2" VALUE="c:\My Documents\Spreadsheets\Book2.xls">
<PARAM NAME="File3" VALUE="c:\My Documents\Spreadsheets\Summary.xls">

Handling Basic Authentication and SSL

When XUpload attempts to upload to a server protected by Basic Authentication, it displays a dialog box asking the user for his/her username and password which are then sent to the server. You can use the Username and Password properties to specify default credentials that will be used by XUpload. If these credentials are valid, XUpload will go ahead with uploading and no login dialog will be displayed. If the credentials are rejected by the server, XUpload will display the login dialog with the User Name and Password boxes populated with the values specified by the Username and Password properties. You may choose to disable the login dialog by setting the ShowLoginDialog properties to False. In that case XUpload will proceed with uploading even if the credentials specified by the Username/Password properties are invalid, so the upload may fail.

If the server requires a Secure Socket Layer connection (SSL) you must set the SSL property to True, as follows:

<PARAM NAME="SSL" VALUE="True">

Proxies and Challenge/Response Authentication

XUpload uses the same WinInet API as Microsoft Internet Explorer, and is programmed to use the same configuration information as IE, so nothing special needs to be done to configure XUpload to work with proxies or Challenge/Response - protected servers.

Preserving Original "Last Modified" Timestamps of Uploaded Files

When browsers upload files to the server they do not send the "Last Modified" dates together with the files, but XUpload does. The control adds a custom header, "X-Last-Date", to the standard "Content-Disposition" and "Content-Type" MIME headers used in form-based uploading. The current version of the AspUpload server component (v 1.3) ignores the custom header, however the next release of the component due in July, 1999 will use it to preserve the original dates of uploaded files.

Using Client-Side VBScript

You may customize the appearance and behavior of XUpload on your Web page using client-side VBScript. The following code disables the control's popup menu and creates four buttons with the same functionality as the menu's items:
 
<SCRIPT LANGUAGE="VBScript">
Sub Select_OnClick
  UploadCtl.Select
End Sub

Sub Remove_OnClick
  UploadCtl.RemoveHighlighted
End Sub

Sub RemoveAll_OnClick
  UploadCtl.RemoveAll
End Sub

Sub Upload_OnClick
  UploadCtl.Upload
End Sub
</SCRIPT>

<HTML><BODY>

<OBJECT WIDTH=500 HEIGHT=200
 ID="UploadCtl" CLASSID="CLSID:E87F6C8E-16C0-11D3-BEF7-009027438003" CODEBASE="XUpload.ocx">
<PARAM NAME="EnablePopupMenu" VALUE="False">
</OBJECT>
<P>
<INPUT TYPE=BUTTON NAME="SELECT" VALUE="Select">
<INPUT TYPE=BUTTON NAME="REMOVE" VALUE="Remove">
<INPUT TYPE=BUTTON NAME="REMOVEALL" VALUE="Remove All">
<INPUT TYPE=BUTTON NAME="UPLOAD" VALUE="Upload">

</BODY></HTML>

Including Non-File Form Items

It is often necessary to upload additional information together with the files, such as a text description. In browser-based uploading, this is handled by adding non-file items to the HTML form, for example:

<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="UploadScript.asp">
File 1:<INPUT TYPE=FILE NAME="FILE1">
File 2:<INPUT TYPE=FILE NAME="FILE2">
Description:<INPUT TYPE=TEXT NAME="DESCR">
<INPUT TYPE=SUBMIT VALUE="Upload!">
</FORM>

With the help of client-side VB script, XUpload can emulate non-file form items using the method AddFormItem( name, value). When the Upload button is clicked, our VB Script must collect data from the form items on the page and pass them to the XUpload control via the AddFormItem method, but first it needs to remove all the form items that might have been passed to the control by previous uploads. This is done by calling RemoveAllFormItems. Suppose our page contains the following form items besides the four buttons mentioned in the previous example:

...
Description: <INPUT TYPE=TEXT NAME=DESCR><BR>
Save in Database? <INPUT TYPE=CHECKBOX NAME=YESNO><P>

The Upload_OnClick subroutine now may look like this:

<SCRIPT LANGUAGE="VBScript">
...
Sub Upload_OnClick
UploadCtl.RemoveAllFormItems
If YESNO.Checked Then UploadCtl.AddFormItem "YESNO", "on"
UploadCtl.AddFormItem "DESCR", DESCR.Value
UploadCtl.Upload
End Sub
</SCRIPT>

The file FormItems.htm included with the control demonstrates this technique.

If ASP is used on the server side, we cannot access the non-file form items using the Request.Form collection because of the special data format used in file uploading. AspUpload provides a Form collection of its own: Upload.Form("DESCR"). For more information on handling non-file form items, see AspUpload Manual.

Handling Events

XUpload fires events on every major occasion such as the beginning and end of an upload, addition and deletion of files, sorting, errors, etc. With the help of VBScript, your web page can handle some or all of the events. The following example replaces the default Reply from Server message by handling the ServerReply event:
 
 
<SCRIPT LANGUAGE="VBScript">
Sub UploadCtl_ServerReply(Reply)
MsgBox("The reply form the server was: " & chr(13) & chr(10) & Reply)
End Sub
</SCRIPT>

<HTML>
<BODY>

<OBJECT WIDTH=500 HEIGHT=200
 ID="UploadCtl" CLASSID="CLSID:E87F6C8E-16C0-11D3-BEF7-009027438003" CODEBASE="XUpload.ocx">
<PARAM NAME="ViewServerReply" VALUE="False">
<PARAM NAME="Server" VALUE="127.0.0.1">
<PARAM NAME="Script" VALUE="/xupload/uploadscript.asp">
</OBJECT>

</BODY>
</HTML>

For the complete list of events supported by XUpload, see Object Reference below.
 

Using XUpload in VB

Run Visual Basic, open or create a project, and go to Projects/Components. Check the box next to "Persits Software XUpload Control", then click OK. The control's icon (blue dotted square) appears on the VB Toolbox. Use XUpload as you would any VB control. XUpload's properties can be set using VB's standard Properties panel, or XUpload's custom property sheet. The latter can be invoked by right-clicking on the control and selecting "Properties" from the context menu or double-clicking the word (Custom) in the VB Properties panel.

The property sheet can also be invoked programmatically by calling the DisplayProperties method.

Using XUpload as a Server Component

XUpload can work as a server component that can be used in an ASP environment. The following sample ASP code uploads two files from one server (where it is installed) to another (where the upload script is installed):
 
<%
Set XUpload = Server.CreateObject("Persits.XUpload")
XUpload.Server = "127.0.0.1"
XUpload.Script = "/xupload/uploadscript.asp"

' Specify files to upload
XUpload.AddFile "d:\somefile.txt"
XUpload.AddFile "d:\about.txt"

' Perform the upload
XUpload.Upload

' Display the reply
Response.Write "Reply from the Server was: " & XUpload.ServerReply
%>

A more detailed example can be found in the file ServerComponent.asp found in the XUpload package.

NOTE: The XUpload methods Select, Remove, RemoveHighlighted, and DisplayProperties involve XUpload's GUI and may not be called when the control is used as a server component. The methods AddFile, RemoveAll, Upload, AddFormItem, RemoveAllFormItems and MakeHttpRequest are allowed. For more information on the MakeHttpRequest, see section Complimentary Features.

Using XUpload to Upload Files Directly from Windows File Explorer

A shell extension is a Win32 application that, among other things,  adds a custom menu item to the context menu displayed by File Explorer when a user right-clicks on a file or selection of files. When the user selects this menu item the shell extension (or some other application) opens up and performs a certain task on the selected file(s). For example, WinZip and Norton AntiVirus work as shell extensions.

XUpload is also capable of acting as a shell extension which allows you to select files for uploading directly from Windows File Explorer. To register XUpload as an active shell extension, execute the following command from the MS DOS prompt or Start/Run box:

c:\path\XUploadShell.exe -RegServer

This command is silent and generates no feedback to the user. Once this is done, you can fire up File Explorer, select a few files and right-click on them. The context menu will now look similar to this:


 

When you select the "Upload with XUpload" item, a dialog-based application titled "XUpload Shell Application" comes up which contains the XUpload control populated with the selected files, and the buttons "Select", "Remove", "Remove All", "Upload", "Settings" and "Close". This application is XUploadShell.exe which we have just used to register the shell extension.

When you click on "Settings", the XUpload property sheet comes up which allows you to specify your upload settings. When you exit the dialog your settings are saved in the system registry under the key HKEY_LOCAL_MACHINE\Software\Persits Software\XUpload\Shell Extension and used the next time you invoke the extension. To upload the selected files, simply click on the Upload button or select "Upload" from the XUpload control's popup menu..

To remove the XUpload Shell Extension from your system, execute the command

c:\path\XUploadShell.exe -UnregServer

Unregistering the shell extension does not affect the XUpload control.

Complimentary Features

XUpload's MakeHttpRequest method allows your ASP or VB application to perform arbitrary HTTP requests such as POST and GET. The method returns the output returned from the server as a result of the request. The method can optionally save the output in a file.

The following code sample performs a POST to a remote server and returns the result to the user:
 
<%
Set XUpload = Server.CreateObject("Persits.XUpload")
XUpload.Server = "www.myserver.com"
XUpload.Script = "/mydir/myscript.asp"
Response.Write "Response from Server: " &_
      XUpload.MakeHttpRequest("POST", "param1=value1&param2=value+2")
%>

The following code sample pulls a JPG file from a remote server and saves it in a local directory:
 
<%
Set XUpload = Server.CreateObject("Persits.XUpload")
XUpload.Server = "192.168.1.1"
XUpload.Script = "/somedir/somefile.jpg"
XUpload.MakeHttpRequest "GET", "", "c:\localdir\somefile.jpg"
%>

See section Object Reference for the complete description of the MakeHttpRequest.

Object Reference

XUpload Properties
Property Name Type (Access, Default value) Comments
Server String (RW) Specifies the address of the server where the files are uploaded to.
Script String (RW) Specifies the upload script on the Server.
SSL Boolean (RW, False) Specifies whether the server expects a SSL connection.
Port Integer (RW, 0) Specifies the TCP//IP port on the server to connect to. If not specified, ports 80 and 443 are used for regular and SSL connections, respectively.
Username String (RW) Specifies the default username in case basic authentication is enabled on the server.
Password String (RW) Specifies the default password in case basic authentication is enabled on the server.
ShowLoginDialog Boolean (RW, True) Specifies whether a login dialog box should be shown by XUpload if basic authentication is enabled on the server. If this property is set to False, an upload may fail in case Username/Password are invalid.
EnablePopupMenu Boolean (RW, True) Specifies whether a popup menu should be displayed if the control is right-clicked. If an application chooses to set this property to False, it must provide some other means to invoke the Select, Remove and Upload commands.
ViewServerReply Boolean (RW, True) Specifies whether XUpload should display the Reply from Server message box with the text returned by the upload script.
Directory String (RW) Specifies the default directory for the Select Files dialog.
Filter String (RW) Specified the file type filters for the Select Files dialog in the form of a list of pairs separated by the pipe character ( | ). Each pair specifies the verbal description of a filter and the filter itself as a list of semicolon-separated wildcards. The elements in a pair are separated by the pipe character as well. For example,

"Images (.gif;.jpg)|*.gif;*.jpg|Documents (.doc)|*.doc"

ShowErrors Boolean (RW, True) Specifies whether XUpload should  display error messages. If set to False, no errors will be reported. In this case an application may need to handle the Error event. 
MaxFileCount Long (RW, 0) Specifies the maximum allowed number of files. A zero value indicates no limits.
MaxFileSize Long (RW, 0) Specifies the maximum allowed size of individual files. A zero value indicates no limits.
MaxTotalSize Long (RW, 0) Specifies the maximum allowed total size of files. A zero value indicates no limits.
Extensions String (RW) Specifies a comma-separated list of allowed file extensions. An empty string indicates no limitations.
SelectedFiles Files Collection (R) Returns a collection of File objects. Each object represents a  file on the control's list. The File object supports the following read-only properties: Path, Size, Index (0-based) and Selected (indicates whether the file is highlighted in the list.)
TotalFileSize Long (R) Returns the total size of selected files.
FileCount Long (R) Returns the number of selected files
ServerReply String (R) Returns a reply from server once an upload is complete.
Expires Date (R) Returns the control's expiration date. Returns 9/9/9999 if this is a registered copy. If the expiration date cannot be determined returns 0 (displayed as "12:00 AM".)

XUpload Methods
Method  Name Arguments Comments
Upload N/A Has the same effect as choosing "Upload" from the popup menu. Causes the upload process to begin.
Select N/A Has the same effect as choosing "Select" from the popup menu. Causes the Select Files dialog to come up.

This method must not be called if XUpload is used as a server component.

Remove Index As Integer Removes a file with the zero-based index specified by Index from the file list.

This method must not be called if XUpload is used as a server component.

RemoveHighlighted N/A Has the same effect as causing "Remove" from the popup menu. Causes all highlighted items on the file list to be removed.

This method must not be called if XUpload is used as a server component.

RemoveAll N/A Invokes the Remove All command. Clears the file list.
AddFile Path As String Adds a new file to the file list.
DisplayProperties N/A Causes the XUpload property sheet to come up. 

This method must not be called if XUpload is used as a server component.

AddFormItem Name As String
Value As String
Use this method to simulate non-file form items for an upload. See file FormItems.htm for code sample.
RemoveAllFormItems N/A Removes all items added by AddFormItem
MakeHttpRequest Method As String
Params As String
Optional Path = ""
Optional UserAgent = "XUpload"
Optional Headers = ""

Returns: String

Performs an HTTP request using the properties Server, Script, Port, Username and Password. Method specifies the request type such as "GET" or "POST". Params specify the data to be sent to the server. Leave this parameter empty if Method is "GET". Path, if not empty, instructs the method to save the output in a file. UserAgent and Headers, if not empty, specify additional information to be sent to the server.

Returns the output received from the server.

XUpload Events
Name Arguments Comments
Sort Column As Integer Fired when the file list is sorted. If Column is 0 the sorting is by File name, otherwise the sorting is by size.
AddFiles Number As Integer,
Size As Long
Fires when files are added to the file list. Number specifies the number of files being added, Size specifies total size. 
RemoveFiles Number As Integer,
Size As Long
Fires when files are removed from the file list. Number specifies the number of files being removed, Size specifies total size.
UploadStart N/A Fires when the upload process starts.
UploadFinish N/A Fires when the upload process ends, but before a reply from the server is received.
UploadProgress FilePercent As Integer,
OverallPercent As Integer
Fires to indicate the upload progress. FilePercent is an integer between 0 and 100 that specifies the progress of an individual file. OverallPercent is a integer between 0 and 100 that specifies the overall progress.
UploadFile FileName As String Fires right after a file is opened to be uploaded. FileName specifies the file's full path.
ServerReply Reply As String Fires when a reply is received from the server. Reply specifies the text received.
Error Code As Long, 
Description As String
Fires when an error occurs. Code can be one of the following values:

1 - Too many files selected by Select Files dialog.
2 - Selecting files failed.
3 - Server not specified.
4 - Script not specified.
5 - Opening HTTP session failed.
6 - Error connecting to the server.
7 - Opening HTTP request failed.
8 - Wrong file extension.
9  - Cannot open file.
10 - Sending HTTP request failed.
11 - Cannot open file during uploading.
12 - Error reading file.
13 - Error sending data.
14 - File number exceeds MaxFileCount.
15 - Reserved.
16 - File size exceeds MaxFileSize.
17 - Total file size exceeds MaxTotalSize.
18 - Control expired.

Common WinInet Errors and Trouble-shooting

Error: 12029
Meaning: "Cannot connect."
Solution: Make sure the Server and Script parameters are correct and the network connection is functioning.

Error: 12030
Meaning: "Connection Aborted."
Solution: This error usually means that XUpload's SSL parameter does match the SSL settings of the server. Check whether the server requires an SSL connection, and if so set the SSL property to True.