A Resumable Upload



Resumable Uploading

FileUpEE can resume failed client-to-server and server-to-server uploads. Since browsers do not support resumable uploading, you must use XFileEE on the client to create a client-to-server resumable upload application. This section explains how to create a server-to-server upload application in ASP. See XFileEE Resumable Upload to learn how to create a resumable client-to-server upload with XFileEE and 2-tier Resumable Upload in .NET to learn how to create a resumable two-tier upload in ASP.NET.

An upload may fail because of a network connection failure, or because the upload size was greater than MaxKBytesToCancel. To resume a server-to-server upload, call the Resume method on the web server. Behind the scenes, FileUpEE will send a query to the file server asking for the number of bytes received. The resume request will begin at the point where the file server stopped receiving data.


The Upload Status Databases

When a resumable upload fails, FileUpEE saves information about the upload on both the web server and the file server. When the Resume method is called, FileUpEE will get the status of the upload - the number of bytes uploaded to the file server - from the file server database. FileUpEE will then resume the upload from the point at which it stopped.

There are two ways to set the connection string for an upload status database:

The internet user account must have write access the directory where the databases are held. Make sure that the IUSR_MACHINENAME account has Read, Write, and Delete access to this directory. For security reasons the FileUpEE install package does not grant this access.
The sample databases included with FileUpEE and the databases generated by FileUpEE.CreateDatabase are Access databases. To generate a set of tables for an Oracle or SQL Server database, run the script FileUpEE.sql. The script is included in the folder SoftArtisans\FileUpEE.

Top


Resumable Uploading with XFileEE
Using FileUpEE alone, you can create server-to-server resumable transfer applications. To create a client-to-server resumable upload, use XFileEE. See XFileEE Resumable Upload to learn how to create a resumable client-to-server upload with XFileEE and 2-tier Resumable Upload in .NET to learn how to create a resumable two-tier upload in ASP.NET..
The Client Script

The forms page contains the upload form. The form includes a file <input> field, and a radio <input> field that allows the user to force an upload failure. If you select Yes, the MaxKBytesToCancel(saFileServer) property will be set to 1 KB (on the wev server page) and uploads that are larger than 1 KB will fail.

The web Server Script

The web server script runs on the web server. It includes all upload processing information: the save method (directory or database), save location, etc. The web server sends the upload request to the file server script set by the TargetURL property. The request to the file server is a SOAP message (an XML file).

When Resumable(saWebServer) is set to True, FileUpEE will be able to resume a Web-server-to-file-server upload that was suspended because of a network connection failure, or because the upload size was greater than MaxKBytesToCancel. Resumable is set to False by default. Resumable takes the parameter SATransferStage which specifies the stage of the upload: client-to-Web-server or Web-server-to-file server. In the web server script, before calling ProcessRequest, to enable resumable Web-server-to-file-server uploads, you must set:


oFileUpEE.Resumable(saWebServer) = True

Set oFileUpEE.Resumable(saFileServer) to true on either the web server or the file server, at any point before calling ProcessRequest on the file server. In the sample, Resumable(saFileServer) is set in the web server script:


oFileUpEE.Resumable(saFileServer) = True

A resumable upload application uses two status databases, one on the web server and one on the file server. In the web server code, ResumeConnectionString(saWebServer) sets the connection string for the upload status database on the web server. Set ResumeConnectionString before calling ProcessRequest:


oFileUpEE.ResumeConnectionString(saWebServer) ="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;Data Source=" & _
    Server.MapPath("./FileUpEEWS.mdb")

For a FileUpEE request to be resumable, information about the file transfer must be persisted on all stages of that request. For this reason the FileUpEe.ResumeConnectionString and FileUpEe.Resumable properties must be set for all stages of the upload. Therefore, for a web server to file server request to be resumable, Resumable(saWebServer) and Resumable(saFileServer) must both be set to true. Also, FileUpEe must know that the transfer is resumable before reading the HTTP request, so make sure that these properties are set for a stage of the upload before that stage's ProcessRequest method.

FileUpEE will abort a file upload when the size of the transfer reaches the value of MaxKBytesToCancel. In the web server code MaxKBytesToCancel(saFileServer) is set to 1:


If oFileUpEE.Form("ForceFailure") = "yes" Then 
    oFileUpEE.MaxKBytesToCancel(saFileServer) = 1 
End If

Upload a file that is larger than 1 KB to run a resumable upload. To allow the upload to be resumed, MaxKBytesToCancel(saFileServer) will be reset to a higher value in the resume page code.

FileUpEE generally reads data in chunks greater than 56 KB. To see a true resumable request, set MaxKBytesToCancel to 60 and upload a file greater than 60 KB.

If the upload from web server to file server is suspended, and the user clicks the Resume link, the resume-upload script will be called. When the Resume method is called, a request will be made to the status server script. The response will tell FileUpEE the point at which the upload was suspended. StatusUrl specifies the URL of the status server script. You can set StatusUrl in the web server script, before calling SendRequest, or in the resume-upload script, before calling Resume. In this sample, StatusUrl is set in WebServer.asp:


oFileUpEE.StatusURL = "http://localhost/fileupee/samples/" & _
    "uploadsamples/intermediate/resume/asp/status.asp"

If the upload stops before it is complete, a listing script is called is called which displays all suspended uploads and a Resume link for each.


If eSAResult <> saAllProcessed Then 
    Response.Write("<P ALIGN=center><B>Error!</B>Your upload has failed.") 
    Response.Write("Click <a href=""listresumable.asp"">here</a> to see if the _
        transfer is resumable.</P>") 
End If
The Response to a Suspended Upload

If the upload stops, the listing script displays a table of all suspended uploads, with a Resume link for each upload. Clicking Resume submits a request to the resume script with the specified upload's JobId in the query string.

The Resume Script

Before resuming the upload, MaxKBytesToCancel(saFileServer) is reset to a value that will allow the upload to complete:


oFileUpEE.MaxKBytesToCancel(saFileServer) = 999

The Resume method takes an upload's JobId and uses it to get the suspended upload's status from the database. Resume requests the status from Status.asp (the status URL). The ReturnStatus method in Status.asp returns the upload's status to the Resume method, and Resume then continues the upload from the point at which it stopped.


intSAResult = oFileUpEE.Resume(guidJobID)
The Status Script

When a file transfer is resumed, FileUpEE needs to communicate with a status page on the file server to determine the status of the transfer. The URL of this page is set on the web server through the StatusUrl property. If a suspended upload is resumed, the status page will get the upload status from the status database on the file server:


oFileUpEE.ResumeConnectionString(saFileServer) ="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;Data Source=" & _
    Server.MapPath("./FileUpEEFS.mdb")

To resume the upload, the status script calls FileUpEE's ReturnStatus method:


oFileUpEE.ReturnStatus Request, Response
The status page can be a dedicated web page or the same file server page as you post to during a typical file upload. This page will look up the status of the file transfer in the database, so be sure that FileUpEe's ResumeConnectionString property is set.
The File Server Script

A resumable upload application uses two status databases, one on the web server and one on the file server. In the file server script, ResumeConnectionString(saFileServer) sets the connection string for the upload status database on the web server. Set ResumeConnectionString before calling ProcessRequest:


oFileUpEE.ResumeConnectionString(saFileServer) ="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Persist Security Info=False;Data Source=" & _
    Server.MapPath("./FileUpEEFS.mdb")

Since AutoProcess (the third parameter of ProcessRequest is set to True, the file server script will automatically execute the upload instructions set in the web server script.


oFileUpEE.ProcessRequest Request, True, True

Top

Copyright © 2010 SoftArtisans, Inc. All rights reserved.