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 HTML5/Flash Uploader allows configuring automatic upload resuming with a help of 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 HTML5/Flash 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)).

This method is not so effective if HTML5/Flash Uploader sends all files in a single request. Otherwise it will start resending all selected files from the very beginning, even if it was the last file which has failed. To avoid this, make sure that you upload each file in an individual POST request, i.e. (FilesPerPackageFilesPerPackage (ASP.NET)FilesPerPackage (PHP)filesPerPackage (JavaScript) = 1). If you are uploading extremely large files, use the ChunkSizeChunkSize (ASP.NET)ChunkSize (PHP)chunkSize (JavaScript) to split them into smaller pieces, say, 10MB (or, 10485760 bytes).

Let us describe the advantages of this configuration. When a user selects small files (lesser than 10MB), HTML5/Flash Uploader sends them one by one. In case of a connection problem, only the last unsuccessful file will be resent. However, larger files are broken into chunks of 10MB. E.g. you upload 200MB file and the connection is broken when 95% is complete. In this case, it will resend only last chunk without having to re-upload 190MB which are already on the server. Though, when HTML5/Flash 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.

It is highly recommended to use HTML5/Flash Uploader ASP.NET or HTML5/Flash 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 HTML5/Flash 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).

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

<aur:ImageUploaderFlash ID="Uploader1" runat="server">
	<UploadSettings AutoRecoveryMaxAttemptCount="10" 
$uploader = new ImageUploaderFlash("Uploader1");
var u = $au.imageUploaderFlash({
	id: 'Uploader1',
	uploadSettings: {
		autoRecoveryMaxAttemptCount: 10,
		autoRecoveryTimeout: 2000,
		filesPerPackage: 1,
		chunkSize: 10485760,
		connectionTimeout: 10000

See Also