SAMPLE: Uploading a File to IIS Using a Browser

ID: Q189651

The information in this article applies to:

SUMMARY

The specification in RFC 1867 "Form-based File Upload in HTML" describes the mechanism by which a file may be uploaded from a Web browser to the server. However, to implement this functionality it is necessary to install the Posting Acceptor bundled with Internet Information Server (IIS) 4.0's option pack (under the Site Server Express option) or the Posting Acceptor add-on for IIS 3.0:

   http://www.microsoft.com/windows/software/webpost/post_accept.htm

For those using earlier versions of IIS or wanting functionality beyond just writing the inbound file to disk, the following library is provided as a sample on how to implement the parsing mechanism.

Uploadext.exe is a sample ISAPI extension DLL that implements the necessary parsing routines to break up multi-part data forms. This self- extracting executable contains the necessary project files for an ISAPI Extension DLL using Microsoft Visual C++ 5.0.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ Uploadex.exe (size: 46252 bytes) 

Release Date: JUL-17-1998

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE : How to Obtain Microsoft Support Files from Online Services

There are three ways to upload files to Microsoft Internet Information Server. One is to use the PUT command with the file content (see Q184352 in the REFERENCES section below). However, this method requires that the browser supports the PUT command. The second way is to use the POST command with INPUT=FILE for the input type. The mechanism for this is described in detail in RFC 1867. Internet Explorer 3.02 with File Upload Add-on, Internet Explorer 4.x, and Netscape Navigator 4.x support this method. The third way is to use the Web Publishing Wizard. See documentation at the following Web site:

   http://www.microsoft.com/windows/software/webpost/default.htm

To implement POST mechanism, support for it must be available on the server side. The Posting Acceptor--Cpshost.dll (found as a part of the Site Server Express) or add-on for IIS 3.0--provides such functionality. Unfortunately, it may not provide enough flexibility (for example, if the uploaded data is a collection of images to be posted directly to an image database).

The sample library attached to this article shows how you can implement a similar functionality with ISAPI Extensions. The sample extension will parse out the multi-part data and write to the disk the contents of each part (using the name of the multipart as the file name).

The sample and the classes within the sample makes use of various Standard Template Library (STL) containers. Refer to the Visual C++ 5.0's online documentation regarding STLs.

To test the sample, simply extract the files to a directory, start Visual C++, load the project file (.dsw), and build the .DLL. Once that's accomplished, copy the DLL to the /scripts/ directory of a Web server and the Upload.html file to the /wwwroot/ directory of the same Web server (you may need to edit the Upload.html if you are not using the default paths for IIS). Using either browser supporting "INTPUT=FILE" tag, request the Upload.html from the Web server. Fill out the form and submit the request. If you did not change the source code of the sample DLL, the uploaded files will appear in C:\Temp\.

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q184352
   TITLE     : How to upload files to the Internet Information Server

Additional query words:
Keywords          : kbhttp kbISAPI kbWebServer 
Version           : WINNT:1.0,2.0,3.0,4.0
Platform          : winnt

Last Reviewed: August 15, 1998