Uploading to a Database


FileUpEE allows you to upload to a directory or a database. The SaveMethod property specifies whether to save an uploaded file to a directory or a database column. By default, SaveMethod is set to saDiskFile, meaning that uploaded files will be saved as files in a directory. Set SaveMethod to saDatabase to save an uploaded file as a database BLOB.

To allow file uploads, NTFS permissions must be set appropriately for FileUpEE's temporary and destination directories. For more information, see Security Considerations.

The following example uploads a file from client to Web server to file server and saves the file in the database upload.mdb. You will find this database in FileUpEE\doc-samples\samples. Note that the asp scripts in this example use the include file include.inc.asp.

A 100K size limit has been set on upload samples.

3 Tier Upload to a Database

[View Source: Web Server] [View Source: File Server]

The database upload example includes three scripts:

  • Form.asp
    The upload form.


  • WebServer.asp
    The Web server script. Webserver.asp includes all server-side upload processing instructions.


  • FileServer.asp
    The file server script. FileServer.asp executes the instructions that were set in WebServer.asp.


Form.asp

Form.asp contains the upload form which includes an <input> of type "file" and a comment field. Both the file and the comment will be saved in a database record.

WebServer.asp

WebServer.asp contains all upload processing instructions. The instructions will be executed on the file server. The SaveMethod tells FileUpEE to save the uploaded file as a database BLOB:

	oFileUpEE.SaveMethod = saDatabase

When uploading to a database, always set the database connection string, the name of the table in which to save the file, and the name of the file column within the table. The connection string and table name may be set for the whole upload, or for an individual file within the upload. The file column name is set for each file. In WebServer.asp, the database connection string is set by the per-upload property FileUpEE.DbConnection:

	'--- Application("connString") is a variable defined in 
	'--- doc-samples\global.asa.  It is the path 
	'--- FileUpEE\doc-samples\samples\upload.mdb.
	oFileUpEE.DbConnection = Application("connString")

The table in which to save the upload is set by the per-upload property FileUpEE.DbTableName:

	oFileUpEE.DbTableName = "UploadTable"

The column in which to save the uploaded file must be set for each file in an upload:

	Set oFile = oFileUpEE.Files("myFile")
	...
	oFile.DbFileColumnName = "FileBinary"

DbSchema - a property of the FileEE object - is a collection of name-value pairs representing the column names and values of a database row. Use DbSchema.Add to add or update a database field value. DbSchema.Add takes two parameters - column name and column value. In WebServer.asp, DbSchema.Add is used to insert values in the FileName, ContentType, ByteSize, and Comment columns in the uploaded file's database record:

	'--- These values come from properties of the uploaded file
	oFile.DbSchema.Add "FileName", oFile.ClientFileName
	oFile.DbSchema.Add "ContentType", oFile.ContentType
	oFile.DbSchema.Add "ByteSize", oFile.Size

	'--- This value comes directly from a text form element
	oFile.DbSchema.Add "Comment", oFileUpEE.Form("fileComment")
This example adds a new row to the database for the uploaded file. When updating a row, you must set the properties DbPrimaryKey and DbPrimaryKeyValue. Do not set these values to add a row.
FileServer.asp

FileServer.asp is executed on the file server. FileServer.asp does not include upload processing instructions; it automatically executes the instructions that were set in WebServer.asp and sent from the Web server as a SOAP message. FileUpEE automatically processes the request according to the SOAP message because AutoProcess - the third parameter of ProcessRequest - is set to True:

	objFileUpEE.ProcessRequest Request, True, True
Do not set AutoProcess to True unless the Web server script contains all necessary processing instructions.

Top


See Also

Per-upload database properties: FileUpEE.DbConnection, FileUpEE.DbPrimaryKey, FileUpEE.DbPrimaryKeyValue, FileUpEE.DbSqlCommand, FileUpEE.DbTableName and FileUpEE.SaveMethod.

Per-file database methods and properties: FileEE.DbConnection, FileEE.DbFileColumnName, FileEE.DbIdentityColumnName, FileEE.DbPrimaryKey, FileEE.DbPrimaryKeyValue, FileEE.DbSqlCommand, FileEE.DbTableName, FileEE.SaveAsBlob, FileEE.SaveMethod, and FileEE.DbSchema.

Top


Copyright © 2003, SoftArtisans, Inc.