We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 82,569 times

Contents

Related Categories

POSTing Form Data to a Web Page - Posting a File

LACanadian

Posting a File

As we mentioned earlier, it is possible to emulate the <INPUT type=file> tag using the WinINet API functions. For the most part, the code from the basic example remains the same. The difference is in the header that is included with the request and the format of the data itself.

The header is relatively straightforward. Instead of form encoding the data, the content type shown below indicates that the data can be found in multiple places in the request body. Now the web server will expect blocks of data with some type of boundary marker to separate each one.

sHeader = "Content-Type: multipart/form-data; boundary=913114112" & vbCrLf

The value of the boundary property is used to identify the start and end of the various blocks of data in the request. You can see how it is used in the code sample below. As a quite note to keep you from wasting your time, the dashes before and after the boundary value, as well as the positioning of the vbNewLine variables is critical to the successful functioning of this process. Eight hours of debugging while trying to come up with the correct combination is proof of that.

lpszPostData = "--913114112" & vbNewLine & "Content-Disposition:" & _
    "multipart/form-data; name=""filePath""" & vbNewLine & vbNewLine & _
    "This is a test of the input file post" & vbNewLine & "--913114112--"
lPostDataLen = Len(lpszPostData)

The actual value of the bounday property doesn't make any difference. Just so that you don't find it elsewhere in the request. The name of the input element is defined in the name property. This can be used on the server side (in TestPost.asp, for example) to access the data. Also, if you plan on posting binary data to the form, run the data through the Base64 algorithm. This converts the untransmitable characters to a more verbose, but Internet-friendly sequence of characters.

I am the owner of a small application development consulting company that specialized in the design and implementation of Internet-based applications. While there are others who can make a web site look good, our expertise is in making the site function. This includes infrastructure design, database design and administration, software development and deployment. For the most part, we utilize Microsoft-based languages and tools. And we are skilled enough to have generated two patent applications for our clients.

Comments