Uploading a File to IIS Using a Browser

ID: Q189651


The information in this article applies to:
  • Microsoft Internet Information Server versions 1.0, 2.0, 3.0, 4.0
  • Microsoft Internet Server Application Programming Interface (API)


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 files are available for download from the Microsoft Download Center. Click the file names below to download the files:

Uploadex.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center. 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:

Q184352 How to upload files to the Internet Information Server

Additional query words:

Keywords : kbfile kbhttp kbISAPI kbWebServer kbDSupport kbiis300 kbiis400
Version : winnt:1.0,2.0,3.0,4.0
Platform : winnt
Issue type : kbinfo


Last Reviewed: December 8, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.