Configuring Fail-safe Upload

Sometimes connection problems occur unexpectedly during the upload of files to server. Such problems cause several inconvenient situations which force users to:

  • Resend files manually (by clicking Upload).
  • Send already uploaded files again because it is not guaranteed that such files are saved on a server.
  • Select and upload all files anew in the case if the computer hangs or the light is switched off.

To avoid these situations ActiveX/Java Uploader offers several means to recover the upload process. These means can be configured via the properties of the UploadSettingsUploadSettings (ASP.NET)UploadSettings (PHP)uploadSettings (JavaScript) class. Let us consider them in more detail.

To begin with, we should note that ActiveX/Java Uploader supports hands-free upload recovery by resending the last failed request. Here you just set a number of attempts (AutoRecoveryMaxAttemptCountAutoRecoveryMaxAttemptCount (ASP.NET)AutoRecoveryMaxAttemptCount (PHP)autoRecoveryMaxAttemptCount (JavaScript)) and a time interval between them (AutoRecoveryTimeoutAutoRecoveryTimeout (ASP.NET)AutoRecoveryTimeout (PHP)autoRecoveryTimeout (JavaScript)). Additionally you can use the ReconnectionTextReconnectionText (ASP.NET)ReconnectionText (PHP)reconnectionText (JavaScript) property to specify the text that will be shown while ActiveX/Java Uploader waits to reconnect.

Note

ActiveX/Java Uploader Express does not support automatic upload recovery. See the Upload Suite Editions topic for details.

However, this method is not so effective because ActiveX/Java Uploader sends all files in a single request by default. It means that in case of a connection problem ActiveX/Java Uploader will resend all selected files, even if it was the last file which has failed. We strongly recommend you to use the multiple requests upload mode along with the automatic upload recovery. This upload mode is described in the Sending All Files at Once or in Several Parts in ActiveX/Java Uploader topic. For brevity, we consider the most commonly used configuration of this upload mode: sending each file in a separate package (FilesPerPackageFilesPerPackage (ASP.NET)FilesPerPackage (PHP)filesPerPackage (JavaScript) = 1) and dividing extremely large files into 10 Mb chunks (ChunkSizeChunkSize (ASP.NET)ChunkSize (PHP)chunkSize (JavaScript) = 10485760).

Let us describe the advantages of this configuration. When a user selects small files (lesser than 10 Mb), ActiveX/Java Uploader sends them one by one. And, in case of a connection problem, only the last unsuccessful file will be resent. However, extremely large files (more than 10 Mb) are sent in chunks, which means that ActiveX/Java Uploader will resend only the last chunk while the automatic upload recovery is performed. Though, when ActiveX/Java Uploader has exhausted all attempts, the whole package containing this chunk is considered unsuccessful.

Although you may change the ChunkSize value, you should take into account the following:

  • The increase of this value will increase the amount of data which will be resent in case of a connection problem.
  • The decrease of this value will increase the overhead traffic.
Note

It is highly recommended to use ActiveX/Java Uploader ASP.NET or ActiveX/Java Uploader PHP to handle upload on the server side. Both of them automatically bundle pieces of one file, uploaded in separated chunks, and provide an access to this file as if it was uploaded as a whole.

In most cases ActiveX/Java Uploader resumes the upload process automatically; but if it is impossible (the connection problem appears to be permanent), the last uploading package is considered failed. If it happened, the upload list still contains all the unsent files, including the one which was being sent when the upload was broken, and a user can resend them manually (just by clicking Upload one more time).

Besides, you can extend your ActiveX/Java Uploader configuration to make it resistant to deeper problems, for instance, when a page containing ActiveX/Java Uploader is closed or a computer is rebooted or suddenly turned off. By default, such problems cause clearing of the upload list and make a user select all the files again. Fortunately, ActiveX/Java Uploader can save and restore upload list, even if a totally unexpected problem occured. This feature is described in the Restoring Upload List topic.

The code sample below demonstrates how to configure a fail-safe upload.

ASP.NET
<aur:Uploader ID="Uploader1" runat="server">
	<UploadSettings AutoRecoveryMaxAttemptCount="10" 
		AutoRecoveryTimeout="2000"  
		FilesPerPackage="1"
		ChunkSize="10485760"
		ConnectionTimeout="10000"/>
</aur:Uploader>
PHP
$uploader = new Uploader("Uploader1");
$uploader->getUploadSettings()->setAutoRecoveryMaxAttemptCount(10);
$uploader->getUploadSettings()->setAutoRecoveryTimeout(2000);
$uploader->getUploadSettings()->setFilesPerPackage(1);
$uploader->getUploadSettings()->setChunkSize(10485760);
$uploader->getUploadSettings()->setConnectionTimeout(10000);
$uploader->render();
JavaScript
var u = $au.uploader({
	id: 'Uploader1',
	uploadSettings: {
		autoRecoveryMaxAttemptCount: 10,
		autoRecoveryTimeout: 2000,
		filesPerPackage: 1,
		chunkSize: 10485760,
		connectionTimeout: 10000
	}
});

See Also

Reference

Manual