SaveAsBlob Method

Object: SoftArtisans.FileUp
Syntax: SaveAsBlob([in] ADOField)
Description:

This method saves an uploaded file to a database.

AppendChunk method. Any OLEDB provider that supports the AppendChunk method can be the destination of a SaveAsBlob. FileUpuses late binding to find the AppendChunk method of the recordset member and writes the data using this method. Note that even char and varchar type fields support AppendChunk, although the size is significantly limited.

For Microsoft SQL Server, the column should be of 'image' or 'text' type. his distribution includes a sample SQL script that you can use to create tables for use in uploading files. See the Setup Instructions for uploading to a database on the server.

For Microsoft Access, the column should be 'OLE Object'. You can use the sample Access database included with this distribution (in the Samples directory) for downloading and uploading files.

When writing to BLOB (Binary Large OBject) fields, the ADO Recordset's cursor type must be adOpenDynamic (i.e., 2).

Any size limitations of the BLOB field is imposed by the database.

The uploaded data is stored exactly as sent, with no interpretation.

If there is more than one file being uploaded in a single page, only the first one is saved.

To save multiple files in a single upload, there is an equivalent method for each file object, i.e., fileUpload.Form("File1").SaveAsBlob rs("FileCol").

By default, an uploaded file will overwrite a file on the server with the same name. To prevent this, set OverwriteFilesto False.

Performance Considerations When Uploading to a Database
In general, uploading to a database instead of a file is less efficient, both in terms of disk space and processor time. Due to the caching necessary when processing multiple form and file elements, the upload is saved to a file and then imported into the database. The temporary cache file is then deleted. Uploading to a database also consumes significant memory resources. It is possible that you will get errors like the following when uploading to a database:

"There is insufficient system memory to run this query."

Uploading to a database is best when there are many small files that you wish to catalogue, such as small graphic images. Large uploads are generally best stored in native files.
See Also: ADO.NET and SaveAsBlob
Examples:
ASP <%
Set rsBlob = Server.CreateObject("ADODB.Recordset")
rsBlob.Open "SimpleBlobTable", "AccessUpload", 2, 3

'---
'--- Add new record and update
'---
rsBlob.AddNew
fileUpload.SaveAsBlob rsBlob.Fields("FileCol")

rsBlob.Update
rsBlob.Close
Set rsBlob = Nothing
'...
%>

Copyright © 2010 SoftArtisans, Inc. All rights reserved.