Downloading from a Database |
 |
With FileUpEE, you can download a file from a directory or a database. To download
a file, use the FileUpEE method
TransferFile,
or - as in the following example - the FileEE method
WriteToResponse.
The example downloads a file from the database upload.mdb on the file server.
The file is downloaded to the Web server and then to the client. You will find upload.mdb in
FileUpEE\doc-samples\samples.
Note that the asp scripts in this example use the include file
include.inc.asp.
The database download example includes three scripts:
- Form.asp
The upload form.
- Download.asp
The Web server script. Webserver.asp includes all server-side
download processing instructions.
- FileServer.asp
The file server script. FileServer.asp executes the instructions
that were set in Download.asp.
Form.asp
Form.asp displays a table of all files in the database upload.mdb, and a
Download link for each file. A SQL query is used to get the information
about the files in the database. The query gets the values of the UploadTable columns
ID, FileName, ByteSize, ContentType, and Comment:
Set oConn = Server.CreateObject("ADODB.Connection")
'--- Application("connString") is a variable defined in
'--- doc-samples\global.asa. It is the path
'--- FileUpEE\doc-samples\samples\upload.mdb.
oConn.Open Application("connString")
'--- The RecordSet object oRS contains ID, FileName,
'--- ByteSize, ContentType, and Comment - all the UploadTable
'--- fields except for the actual file.
Set oRS = oConn.Execute("SELECT ID, FileName, ByteSize, ContentType, Comment FROM UploadTable")
'--- If there are no files in the database, this
'--- message will be displayed.
'--- Before you run the database upload sample,
'--- upload.mdb should contain one file. Each time you run
'--- the database upload sample, you will add a file to
'--- upload.mdb.
If oRS.EOF And oRS.BOF Then
Response.Write("There are no files currently in the database.")
Response.End
End If
An HTML table displays the information about the files and a Download link for each
file. Clicking Download sends a request to Download.asp with two values in the
query string - the file name, and the file id:
Response.Write("<TD>[<A HREF=""webserver.asp?name=" &_
oRS.Fields("FileName").Value & "&id=" & oRS.Fields("ID").Value &_
""">Download</A>]</TD>")
Download.asp
The database upload.mdb is on the file server. The requested file will be downloaded
from the file server to the Web server and then to the client. Download.asp is on the
Web server and contains all download instructions. These will be executed
automatically in FileServer.asp.
The AddDbDownloadFile
method adds a file from a
database to the collection of files to download. AddDbDownloadFile
takes the download destination file name and returns a
FileEE object. Form.asp
got the file's name from the database and sent the name in the query string.
In Download.asp, this name is passed to AddDbDownloadFile:
strFileName = Request.QueryString("name")
...
Set oDownFile = oFileUpEE.AddDbDownloadFile(strFileName)
|
| FileUpEE does not support multiple file downloads. |
|
The file name you pass to AddDbDownloadFile does not have to be
the file name in the database, as it is in this sample. The file name passed
to AddDbDownloadFile is the name that will be displayed to the user
when the file is downloaded.
You can set the database connection string for the upload - using
FileUpEE.DbConnection -
or for the file - using
FileEEDbConnection. In
Download.asp, the connection string is set by the FileEE object's DbConnection
property:
'--- Application("connString") is a variable defined in
'--- doc-samples\global.asa. It is the path
'--- FileUpEE\doc-samples\samples\upload.mdb.
oDownFile.DbConnection = Application("connString")
When downloading a file from a database, to tell FileUpEE where to find the file, you must
set the file's table name, primary key column, primary key value, and file column name:
oDownFile.DbTableName = "UploadTable"
oDownFile.DbPrimaryKey = "ID"
oDownFile.DbPrimaryKeyValue = intFileID
oDownFile.DbFileColumnName = "FileBinary"
After calling AddDbDownloadFile and providing the necessary information
about the file to download, the download request is sent to the file server:
intSAResult = oFileUpEE.SendRequest()
If the Processed property
returns saDownloaded, the file was successfully downloaded from the file
server to the Web server. The
WriteToResponse
method then takes the response from the file server and downloads the file to the client:
'--- If the file was retrieved from the fileserver successfully
'--- stream it down to the client
If oDownFile.Processed = saDownloaded Then
Response.ContentType = "application/unknown"
oDownFile.WriteToResponse Response
Else
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 Download.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
The example uses the method WriteToResponse to download a
file. Alternatively, use the method
TransferFile.
Per-upload database properties: FileUpEE.DbConnection,
FileUpEE.DbPrimaryKey,
FileUpEE.DbPrimaryKeyValue,
FileUpEE.DbSqlCommand,
FileUpEE.DbTableName and
FileUpEE.SaveMethod.
Per-file database properties:
FileEE.DbConnection,
FileEE.DbFileColumnName,
FileEE.DbIdentityColumnName,
FileEE.DbPrimaryKey,
FileEE.DbPrimaryKeyValue,
FileEE.DbSqlCommand,
FileEE.DbTableName, and
FileEE.DbSchema.
Top
Copyright © 2003, SoftArtisans, Inc.