ASPFileForm

ASP multipart (file upload) form parser.
1.2, 2003-04-30

Methods and Properties

ASP.FileForm

Form

A facsimile of the ASP Request Form object. Like that interface, fields can be iterated by number, or by name. Multiple fields with the same name are collected into an array. This is the default property.

Count

Number of items in the Form collection.

length

A synonym for Count.

Collect(MaxBytes)

This method must be called to collect the form data; any reference to the Request Form object before the Collect method is called will consume the form data unsuccessfully. The MaxBytes parameter allows an upper limit on the amount of upload data to accept (for security, performance, and logistical reasons); a value of zero may be given to indicate no limit (not recommended).

CStrW(bstr)

Converts a byte-string to a string (used internally).

CStrB(str)

Converts a string to a byte-string (used internally).

Form Collection Items

Name

The name of the form field.

Value

The value of the form field (file contents, or value of the HTML input). This is the default property.

IsFile

A boolean property that indicates whether this field contains a file.

Filename

The name of the file uploaded (for file fields).

ContentType

The MIME type of the uploaded file (for file fields). Examples: image/png or text/xml.

Size

The size of the field or file, in bytes.

SaveTo(Path)

A convenience method that uses the Scripting.FileSystemObject to write the binary file data to the filename given. Relative paths work as expected via the MapPath method of the ASP Server object.

Examples

Example 1.1. VBScript ASP

<html><head><title>Form Data</title></head><body>
<%
Set FRequest= Server.CreateObject("ASP.FileForm")
FRequest.Collect 0 ' no size restriction 
Response.Write "Form data:<ol>"
For i= 1 To FRequest.Count
  If FRequest(i).IsFile Then
    Response.Write "<li><b>" & FRequest(i).Name & "</b> <tt>" & FRequest(i).Filename _
      & "</tt> " & FRequest(i).ContentType & ", " & FRequest(i).Size & " bytes</li>"
    FRequest(i).SaveTo "form" & i & ".tmp" ' relative path: save alongside this ASP file 
  Else
    Response.Write "<li><b>" & FRequest(i).Name & "</b> " & FRequest(i).Value ' ".Value" can usually be omitted 
  End If
Next
Response.Write "</ol><ul><li><b>title</b> " & FRequest("title") _
  & "</li><li><b>carimage</b> size: " & FRequest("carimage").Size & "</li></ul>"
%>
</body>
</html>

Setup

  1. Download ASPFileForm.wsc to web server (somewhere permanent, like a system directory).

  2. Right-click the file and choose Register.