Miraplacid Scripting Components Manual

 
 

Miraplacid MSCUpload 1.1

MSCUpload is an Active Server File Upload component. It extentds standard Request object capabilities in handling uploaded data.
MSCUpload is a perfect way for ASP applications to handle uploaded files and still make another form fields easily accessable.
To upload file from a client's web browser web page should contain a form with Method="POST" and File input control <INPUT TYPE="FILE">.
Component parse submited data, save files to disk and represent data from form fields as well as information about uploaded files in convinient, easy-to-use form.
User's browser should meet RFC 1867 specification to be able to upload files to server. The most of existing browsers including IE and Netscape are compatible with RFC1867 and can be used to files upload.

Component creation

To create component, use following constructions
  • JScript: var obj = Server.CreateObject("Miraplacid.MSCUpload");
  • VBScript: set obj = Server.CreateObject("Miraplacid.MSCUpload")

Note: Component designed for Apartment threading model. Therefore, the best scope of their using is ASP page level scope.
Using components of version 1.1 in Application and Session scopes may cause problems with your ASP Server (IIS or Chili) productivity.
To learn more about ASP execution scopes, see your ASP Server manual.

Getting started

Let's consider simple HTML form with a few elements to submit to server some text and data.

<HTML>
<BODY BGCOLOR="White">
<FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="uploadscp1.asp">
	<INPUT TYPE=TEXT SIZE=35 NAME="TEXT1"><BR>
	<INPUT TYPE=TEXT SIZE=35 NAME="TEXT2"><BR>
	<INPUT TYPE=FILE SIZE=35 NAME="FILE1"><BR>
	<INPUT TYPE=FILE SIZE=35 NAME="FILE2"><BR>
	<INPUT TYPE=SUBMIT VALUE="Upload">
</FORM>
</BODY>
</HTML>

The first two fields are for text information, the next two is for files, the very last one is just "Upload" button.
You have to specify ENCTYPE="multipart/form-data" attribute to inform browser that you want it to send to server specified files together with fields data. Otherwise it just send a text from form fields.

Server side script is pretty simple:

<%@ LANGUAGE=VBScript %>
<HTML>
<HEAD>
<TITLE>Simple upload response #1</TITLE>
</HEAD>
<BODY BGCOLOR="White">
	<H2>Simple response</B></H2>
<HR size="1" color= "Black">
<%
    Set oUpload = Server.CreateObject("Miraplacid.MSCUpload")
    oUpload.ProcessPostData()
    Response.Write("Elements arrived: " & oUpload.Form.Count() & "<br>")
    Response.Write("Files arrived: " & oUpload.Files.Count() & "<br>")
%>
</BODY>
</HTML>

All you need to do is just create MSCUpload object and call ProcessPostData() method.

Work with files and form data

Let's modify our example a little bit to show how to work with files and form data.
In this example we'll get all the information from MSCUpload object.

<%@ LANGUAGE=VBScript %>
<HTML>
    <HEAD>
    <TITLE>Simple upload response #2</TITLE>
    </HEAD>
<BODY BGCOLOR="White">
	<H2>Simple response</H2>
    <HR size="1" color= "Black">

<%
    Set oUpload = Server.CreateObject("Miraplacid.MSCUpload")
    oUpload.ProcessPostData()
 
%>
	<H3>Look at text arrived</H3>
 
<%
    For Each Index1 In oUpload.Form
       For Each Element In oUpload.Form(Index1)
          Response.Write("Text element " & Index1 & ": " & Element & "<br>")
       Next
    Next
%>
 
    <H3>Look at files arrived</H3>
<%
    For Each Index2 In oUpload.Files
       Set FileInfo = oUpload.Files(Index2)
       Response.Write("File element " & Index2 & ": <br>")
       Response.Write("User path: " & FileInfo.UserPath & "<br>")
       Response.Write("Tmp (server) path: " & FileInfo.TmpPath & "<br>")
       Response.Write("Size " & FileInfo.Size & "<br><br>")
    Next
%>
 
</BODY>
</HTML>

Like in the previous example let's create MSCUpload object and call ProcessPostData() method. Then go through elements of object Form (they are actually collection). Then let's go through elements in object Files.
Files is actually a collection of MSCFileInfo objects. You can see how simple you can access all the information about your files.

Saving to Database

Use MSCBlob object to save any binary data (including uploaded files) to database.

<%
    Set oUpload = Server.CreateObject("Miraplacid.MSCUpload")
    oUpload.ProcessPostData()

    Set oBlob = Server.CreateObject("Miraplacid.MSCBlob")
    oBlob.LoadFromFile oUpload.Files("FILE1").TmpFile

    ' Connect to DB using ADO
    ' Create oRs object wich is Recordset
    ' Prepare it for updating

    Set oRs = Server.CreateObject("ADODB.Recordset")
    oRs.Open <Your SQL statement>, <Your connection string>, 2,3

    oRs.Field(2).Value = oBlob.Bin
    oRs.Update()
    oRs.Close()
    oRs.ActiveConnection.Close()
%>

Object reference


Property Type Description
Form Collection of Varaints Provides access to Form fields.
The same as Request.Form
Files Collection of Varaints Provides access to MSCFileInfo objects collection. These objects contain complete information about the uploaded files. Could be iterated with key or integer index.
IMPORTANT: HTML form can't contain several FILE elements with the same name.

Method Parameters Return Value Description
ProcessPostData None None Parse and process uploded data. Shall be called before the Forms and Files property reading.
IMPORTANT: This function call makes impossible to use Request object to obtain forms data. Use oUpload.Form instead of Request.Form.

MSCFileInfo Object reference

Auxiliary object. Contains information about files received by MSCUpload component.

Property Type Description
UserPath String Contains file path on user's PC.
TmpPath String Contains file path on on a server. It's an actual location of the uploaded file.
Size Long Uploaded file size

 
 
Technical Support   Copyright © 2001, 2002 by Miraplacid