The information in this article applies to:
SUMMARYThere are several options available for uploading files to Internet Information Server (IIS) programmatically from client applications. This articles presents some of these options, and describes how to employ HTTP PUT functionality. MORE INFORMATIONUsing the WebPost APIsOne method for uploading files is by using the WebPost APIs, with either the HTTP POST method or the ActiveX upload control. The WebPost APIs are fully documented and explained in Internet Client SDK.The drawback is that both of these methods require that the server have a special component that handles posted data and saves it in a file on the server's file system. The exceptions are WebPost and ActiveX control uploading when using an FTP posting provider. However, this requires installing and configuring an FTP server in addition to the WWW server. The Microsoft Posting Acceptor shipped with Windows NT 4.0 Option Pack (NTOP) provides the back-end functionality for file uploads via the methods described above. Please see the NTOP documentation and Microsoft Posting Acceptor release notes (also shipped with NTOP) for information on how to configure and use Posting Acceptor and File upload control. By Using HTTP Protocol PUT FunctionalityThe HTTP protocol PUT functionality method does not require any components on the server to handle upload data. The PUT functionality is built-in to IIS 4.0. Please note that not all Internet Browsers can handle the HTTP PUT verb. The following discussion applies to applications written with the WinInet APIs, which give the programmer the ability to create and send an HTTP request programmatically.The PUT method is described in the HTTP/1.1 RFC 2068 (http://www.w3c.org/Protocols/rfc2068/rfc2068) With this method the client supplies a URL and sends the data in the body of the request. The main difference between POST and PUT is that with PUT, the URL is not the name of a server application that will handle the client's data. Instead, the URL is the name of the file that will be created by the server to store the received data. If the URL already exists, then it will be overwritten by the server. Please note that the virtual directory referred to in the URL must have WRITE permission set (for IIS 4.0, this is configurable via Directory Properties in MMC). For example, the following HTTP request (only verb and URL is shown) creates Page.htm file in the /test virtual directory. File will contain data sent with the request:
Because WinInet APIs enable the programmer to create any valid HTTP request, they can be easily used to upload data to the server. The following steps need to take place:
Upon running this code, IIS 4.0 will create the file Page.htm in virtual directory /test. The file will contain the "Hello, World!" string. Please note that HttpSendRequest can be used only with a single buffer of limited size. HttpSendRequestEx and InternetWriteFile can be used to send buffers of any size as follows:
NOTE: IIS may lock a file immediately after it processes the GET request. Therefore, in the following sequence of requests, the second PUT may fail:
Even though the failure is caused by locking violation, IIS may report it as error caused by ACL on the resource (error 401.3). To prevent this problem, the following methods can be used:
REFERENCESFor additional information, please see the following article(s) in the
Microsoft Knowledge Base: Q177188 FILE: Using HttpSendRequestEx for Large POST Requests(c) Microsoft Corporation 1998, All Rights Reserved. Contributions by Leon Braginski, Microsoft Corporation Additional query words: UPLOAD Posting Acceptor PUT
Keywords : |
Last Reviewed: April 26, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |