iASP_Upload Component

Overview

The iASP_Upload component is meant for file uploading. The iASP's Server.CreateObject provides the facility to instantiate this component, after which all methods and properties can be accessed.

    Example:

    <% Set obj= Server.CreateObject("Persits.Upload") %>

The iASP_Upload component consists of two major classes:

The above two classes hold all the general information about the uploaded files.

METHODS:

PROPERTIES:

Method Descriptions

Method Signature: int save([in]String   tempDirectory)

This method saves all the files browsed in a single upload to the temporary directory with their original file names and returns the number of total files uploaded.

Multiple file upload example:

Html page:

     <HTML>  <HEAD>
     <TITLE>Multiple File Upload via iASP_Upload</TITLE>
     </HEAD>
     <BODY>
     <form enctype="multipart/form-data" method="post" action="sample2.asp">
     Enter filename to upload: <input type="file" name="file1"><br>
     Enter filename to upload: <input type="file" name="file2"><br>
     Enter filename to upload: <input type="file" name="file3"><br>
     <input type="submit">
     </form>
     </BODY>
     </HTML>

Script for 'sample2.asp':

   <HTML><HEAD>
   <TITLE>Uploading Multiple Files </TITLE>
   </HEAD>
   <BODY>
   <%
      Set obj = Server.CreateObject("Persits.Upload")
      obj.save "c:\temp"   
' Saving all files at once
   %>

   <BR>
   Thank you for uploading your file.
   </BODY>
   </HTML>


Method Signature:  int saveVirtual([in]String   virtualDirectory)

This method saves all the files browsed in a single upload to the virtual directory with their original file names and returns the number of total files uploaded.

Multiple file upload example:

Html page:

   <HTML>  <HEAD>
   <TITLE>Multiple File Upload via iASP_Upload</TITLE>
   </HEAD>
   <BODY>
   <form enctype="multipart/form-data" method="post" action="sample2.asp">
   Enter filename to upload: <input type="file" name="file1"><br>
   Enter filename to upload: <input type="file" name="file2"><br>
   Enter filename to upload: <input type="file" name="file3"><br>
   <input type="submit">
   </form>
   </BODY>
   </HTML>

Script for 'sample2.asp':

   <HTML><HEAD>
   <TITLE>Uploading Multiple Files </TITLE>
   </HEAD>
   <BODY>
   <%
      Set obj = Server.CreateObject("Persits.Upload")
      obj.saveVirtual "c:\VirDir"
   %>

   <BR>
   Thank you for uploading your file.
   </BODY>
   </HTML>


Method Signature:  String form([in]String fieldname)

This method works equivalent to ASP's Request.Form("fieldname") and returns the value of the non-file field specified in the argument of 'form' method.

Example: getting the values of the Form fields:

Html page:

   <HTML><HEAD>
   <TITLE>Getting values of fields </TITLE>
   </HEAD>

   <BODY>
   <FORM enctype="multipart/form-data" method="post" action="sample2.asp">
   <SELECT NAME="CHIOICE" >
   <OPTION>Image
   <OPTION>Text
   <OPTION>Source Code
   <OPTION>Archive
   </SELECT>
   <BR>
   <INPUT TYPE=TEXT NAME="DESCRIPTION"><BR>
   <INPUT TYPE=FILE NAME="FILE1">
   <BR>
   <INPUT TYPE="submit">
   </FORM>
   </BODY>
   </HTML>

Script for 'sample2.asp':

   <%
      Set obj = Server.CreateObject("Persits.Upload")
      choice=obj.form("CHOICE")
      des=obj.form("DESCRIPTION")

      Response.Write choice
      Response.Write des
   %>


Method Signature:  UploadItem[]   form()

This method returns the array of  UploadItem, which holds all the information about the fields of the Form. This information includes  names  and  values  of the fields.

Example: getting UploadItem class array:

Html page:

   <HTML><HEAD>
   <TITLE>Getting values of fields </TITLE>
   </HEAD>

   <BODY>
   <FORM enctype="multipart/form-data" method="post" action="sample2.asp">
   <SELECT NAME="CHIOICE" >
   <OPTION>Image
   <OPTION>Text
   <OPTION>Source Code
   <OPTION>Archive
   </SELECT>
   <BR>
   <INPUT TYPE=TEXT NAME="DESCRIPTION"><BR>
   <INPUT TYPE=FILE NAME="FILE1">
   <BR>
   <INPUT TYPE="submit">
   </FORM>
   </BODY>
   </HTML>

Script for 'sample2.asp':

   <%
      Set obj = Server.CreateObject("Persits.Upload")
      For Each Item in obj.form    'returns an array of UploadItem
         If Item.Name = "CHIOICE" Then
            Response.Write Item.Value & "<BR>"
         End If
      Next
   %>


Method Signature:   UploadedFile[]  Files()

This method returns an array of UploadedFile which contains the information of uploaded files. Various methods can be invoked on the UploadedFile object.

Example: getting UploadedFile class array

   <%
      For Each File in Upload.Files   
' Returns an array of file class
         ...
         
' Calls to methods of file class
         ...
      Next
   %>

 

Method Signature:  void fromDatabase([in]String connectString, [in]String queryString, [in]String path)

This method exports a BLOB field from a database table to server  hard disk. The connectString is the proper Connection String in the format "DSN=DSNName;PWD=;UID=;" for the database, the querystring is the proper select query that returns ateast one BLOB record, whereas, path specifies the destination path.
 
Example: saving a database record

Html page:

   <HTML> 
   <HEAD>
   <TITLE>Multiple File Save to the DataBase via iASP_Upload</TITLE>
   </HEAD>
   <BODY>
   <form enctype="multipart/form-data" method="post" action="sample2.asp">
   Enter filename to upload: <input type="file" name="file1"><br>
   Enter filename to upload: <input type="file" name="file2"><br>
   Enter filename to upload: <input type="file" name="file3"><br>
   <input type="submit">
   </form>
   </BODY>
   </HTML>

Script of 'sample2.asp':

   <%
      Set obj = Server.CreateObject("Persits.Upload")
      count=0
      obj.save "c:\temp\"
      For Each File in obj.files
         Upload.fromDatabase "BlobTest","select BlobF from Blob where index=18","c:\images\aaa.gif"
         File.delete
      Next
   %>



Property Descriptions

Property Signatures:    int getMaxSize() and void setMaxSize(int  maxSize)

This is a Read/Write property.  Maximum bytes to be transferred to the Server can be retrieved and set according to the requirement. The files greater than maxSize get truncated and only maxSize bytes are transferred.

Example: setting maxSize for files

Html page:

   <HTML> 
   <HEAD>
   <TITLE>Multiple File Upload via iASP_Upload</TITLE>
   </HEAD>
   <BODY>
   <form enctype="multipart/form-data" method="post" action="sample2.asp">
   Enter filename to upload: <input type="file" name="file1"><br>
   Enter filename to upload: <input type="file" name="file2"><br>
   Enter filename to upload: <input type="file" name="file3"><br>
   <input type="submit">
   </form>
   </BODY>
   </HTML>

 

Script for 'sample2.asp':

   <%
      Set obj = Server.CreateObject("Persits.Upload")
      obj.setMaxSize  1024*1024        ' Up to 1 megabyte
      obj.save "c:\temp\"
   %>


Property Signatures:    boolean  getOverWriteFiles() and void setOverWriteFiles(boolean overwrite)
 

This is a Read/Write property.  By default, this property is set true i.e. any file having the same name as that of uploaded file will be over written. However this can be set to false as per requirement.

Example: setting overWriteFiles for files

Html page:

   <HTML> 
   <HEAD>
   <TITLE>Multiple File Upload via iASP_Upload</TITLE>
   </HEAD>
   <BODY>
   <form enctype="multipart/form-data" method="post" action="sample2.asp">
   Enter filename to upload: <input type="file" name="file1"><br>
   Enter filename to upload: <input type="file" name="file2"><br>
   Enter filename to upload: <input type="file" name="file3"><br>
   <input type="submit">
   </form>
   </BODY>
   </HTML>

 

Script for 'sample2.asp':

   <%
      Set obj = Server.CreateObject("Persits.Upload")
      ow=obj.getOverWriteFiles
      if ow = true
         obj.setOverWriteFiles false    ' Save files with unique names
      end if
      obj.save "c:\temp\"
   %>

If you require technical support please send complete details about the problem you are having to support@halcyonsoft.com.


Copyright © 1998-2002, Halcyon Software Inc. All rights reserved.