Resumable Uploading |
New in V3*This feature is not available in JFileSE. |
JFile Enterprise Edition (JFileEE) includes resumable uploading and resumable downloading. In a resumable upload, if the file transfer fails, JFile will display a pop-up dialog containing an error message, a "Resume" button, and a "Cancel" button. If the user clicks "Resume," JFile will try to continue the upload from the point at which it stopped.
When you create a resumable upload application with JFileEE, you must use FileUpEE to handle the server-side file transfer processing. |
In a resumable upload, JFile caches the files to be uploaded in a temporary directory on the client before starting the upload. JFile creates the temporary directory under the current user.home folder (for example, C:\Documents and Settings\[UserName]\JFileResumeDir\ on Windows 2000 or higher with Sun JVM). User.home is a JVM system property.
On the server, FileUpEE saves information about the upload in a status database. When the upload is resumed, FileUpEE gets the status of the upload - the number of bytes uploaded to the server - from the status database. FileUpEE then sends the upload status to JFile, and JFile resumes the upload from the point at which it stopped. The upload status database FileUpEEWS.mdb is included in the JFile samples directory.
A resumable upload includes:
To enable resumable uploading, in your JFile upload submission script:
The following is a simple resumable upload script:
<APPLET codebase="/JFileScripts" code="softartisans.filetransfer.UploadClient.class"
height="0" width="0" mayscript archive="filetransfer.jar" name="fileupload">
<!-- The Cabbase parameter specifies the cab file containing the applet. -->
<PARAM name="cabbase" value="filetransfer.cab">
<!-- The PostURL parameter specifies the URL to which the file will be posted. -->
<PARAM name="PostURL" value="http://localhost/jfilescripts/formresp.asp">
<!-- The FileName# parameter specifies a file to transfer. When uploading more than one file, use
"FileName1," "FileName2," etc. -->
<PARAM name="FileName1" value="c:\images\file.gif">
<!-- Set to ManuallyResumable to 1 to allow the upload to be manually resumed. -->
<!-- If the upload fails, JFile will display a dialog asking if -->
<!-- the user would like to retry the upload -->
<PARAM name="ManuallyResumable" value="1">
</APPLET>
When you create a resumable upload application with JFileEE, you must use
FileUpEE to handle the server-side file transfer
processing. For complete instructions on creating a FileUpEE upload processing
page, see the FileUpEE documentation. To enable JFile to FileUpEE resumable uploading,
include the following in your FileUpEE script, before calling FileUpEE's
ProcessRequest
method:
Resumable(saWebServer)
property to true
.ResumeConnectionString(saWebServer)
property to the
connection string for the upload status database on the Web server. ReturnStatus
method to send the status of a failed
upload back to JFile.ReturnStatus
should be called only when an upload fails and the
user clicks JFile's "Resume" button. To determine whether ReturnStatus
should be called, check if the request to the FileUpEE page
(the PostURL) is a HEAD request or a POST request.
Before resuming an upload, JFile sends a HEAD request to the
PostUrl page requesting status information. So, if the request method is
HEAD, call ReturnStatus
. FileUpEE's ReturnStatus
method
sends the number of bytes received on the server and JFile resumes the upload
from the point at which it stopped.
To demonstrate a resumable upload, the following FileUpEE script forces a transfer failure.
When the upload is submitted for the first time, FileUpEE's MaxKBytesToCancel
property
is set to a low value, forcing a network error on the server.
When the failed upload is resumed, JFile sends the header HTTP_RANGE with the upload
request. To determine whether an upload request is a first request or a resumed upload,
the sample FileUpEE code checks whether the HTTP_RANGE header was sent with the request.
If it was not, MaxKBytesToCancel
is set to force an upload failure. If HTTP_Range was
sent, MaxKBytesToCancel
is not set, allowing the upload to succeed.
|
|
The following lines are from a FileUpEE resumable upload script. A complete resumable upload application is included in the JFile samples directory.
<%
Set oFileUpEE = Server.CreateObject("SoftArtisans.FileUpEE")
oFileUpEE.TransferStage = saWebServer
'-------------------------------------------------------------------------------------------
'--- Set these properties to activate Client-to-WebServer resumability for JFile
'-------------------------------------------------------------------------------------------
oFileUpEE.Resumable(saWebServer) = True
'--- Set the connection string for the webserver's resume database
oFileUpEE.ResumeConnectionString(saWebServer) = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;Data Source=" & _
Server.MapPath("./FileUpEEWS.mdb")
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
'--- This block is the "STATUS" portion of the resume webserver page.
'-------------------------------------------------------------------------------------------
'--- Before resuming a transfer, JFile sends a HEAD request to the PostURL
'--- (this page) requesting status information. FileUpEE's ReturnStatus
'--- method sends the upload status to JFile. After the status is received,
'--- JFile initiates the resume POST.
If Request.ServerVariables("REQUEST_METHOD") = "HEAD" Then
oFileUpEE.ReturnStatus Request, Response
Response.End
End If
'-------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------
'--- This If block forces an upload failure and is here only to demonstrate resumability
'-------------------------------------------------------------------------------------------
'--- This forces a failure in order to demonstrate resumability.
'--- You do NOT need this in your production application.
If Request.ServerVariables("HTTP_RANGE") = "" Then
'--- If the HTTP_RANGE header isn't detected, it's a normal request
'--- We will make it fail so that resumability can be demonstrated
oFileUpEE.MaxKBytesToCancel(saWebServer) = 1
Else
'--- If the HTTP_RANGE header is detected, reset the MaxKBytesToCancel
'--- value so that it will succeed
oFileUpEE.MaxKBytesToCancel(saWebServer) = 9999
End If
'-------------------------------------------------------------------------------------------
'--- The following lines receive the resumed upload, name the uploaded file,
'--- and save it on the server.
oFileUpEE.ProcessRequest Request, False, False
oFileUpEE.DestinationDirectory = Server.MapPath("/JFileEE/samples/temp")
For Each oFile In oFileUpEE.Files
oFile.DestinationFileName = oFile.ClientFileName
oFile.Save
Next
Response.Write "<H2 ALIGN=center>Upload results</H2>"
'--- If SAResult is saAllProcessed, then all of the files were processed correctly
If intSAResult = saAllProcessed Then
Response.Write "<H3>FileUpEE Processed All Files Successfully</H3>"
Else
Response.Write "<H3>There was an error processing one or more files</H3>"
End If
...%>
When a resumable JFile to FileUpEE upload fails, FileUpEE saves information about
the upload in a status database on the server. When the user clicks JFile's "Resume"
button, FileUpEE gets the status of the upload - the number of bytes uploaded to the
file server - from the status database. FileUpEE's ReturnStatus
method returns
this information to JFile, and JFile resumes the upload from the point
at which it stopped. The upload status database FileUpEEWS.mdb is included in the JFile
samples directory.
Copyright © 2000-2003 SoftArtisans, Inc. All rights reserved.