6) Use Partial Uploads.

 

back to main index

 

Partial uploads give the powerful ability for users to successfully upload and deal with part of the request even when some severe IO Error occurs part way through uploading. This means that the whole upload does not have to start from the beginning again which will inconvenience users of an application. You use partial uploads by selecting the correct XloadManager constructor that has a boolean argument that allows partial uploads to occur (see code below).

 

IMPORTANT:- The default setting for partial uploads within Xload is to NOT allow them, which means that when any IO Error occurs, all file deployments of any kind are destroyed and the system is put back to before the request was made and an IOException is thrown by the upload() method essentially killing processing of the request. When partial uploads ARE being allowed then any previous uploads or ordinary parameters read before any IO Error occurred will remain on the server to be processed and not be destroyed. The IO Error  can then become a reason for upload failure for a particular part of the upload process and the upload() method returns normally. In this case a response should always be sent as the client/server connection may still exist and detailed information can be gathered if required about which uploads have failed or not even attempted. But, be pragmatic in these situations as most of the time a partial upload occurs with a breakdown between the client/server connection and no response can then be sent nullifying the effort input to create some detailed report.

 

IMPORTANT:- Please note that an IO Error can occur at any time during the request and not just when uploading a file, which means that if ordinary request parameters were sent with the request then an IO Error may have occurred while sending these. So even though a file may have uploaded correctly some request parameters may not exist.

 

Partial uploads are simple to implement and deal with as is shown in the code below.

 

 

XloadManager xman = new XloadManager(request, true);

xman.target("file1", "uploaded");

xman.target("file2", "uploaded");

xman.upload();

 

List successfulUploads = xman.getSuccessfulFileUploads();

Iterator it = successfulUploads.iterator();

while(it.hasNext()){

XloadFileUpload upload = (XloadFileUpload)it.next();

//deal with successful uploads

}

 

if(xman.hasPartialUploadOccurred()){

//deal with partial upload situation.

}

 

//send a response to the user

 

 

 

 

 

where:

request - HttpServletRequest object.

uploaded - Directory to upload files to (relative to the web application directory).

file* - File parameter inside html (or other) form.

 

 

The above code snippet shows how elegant and easy it is to handle this complex situation with Xload and partial uploads. No exceptions are thrown, Xload just provides methods to access all successful uploads and also to determine if a partial upload has occurred. When a partial upload occurs, any files that have been specifically targeted and are not uploaded because they have not been reached before the IO Error has occurred, are termed as redundant and can be accessed by the use of the following code snippet.

 

 

XloadManager xman = new XloadManager(request, true);

....

...

xman.upload();

....

...

if(xman.hasPartialUploadOccurred()){

List list = xman.getRedundantTargetUploads();

//deal with redundant uploads

}

 

 

 

 

where:

request - HttpServletRequest object.

 

IMPORTANT:- The above code works in close conjunction with upload failure handling code (i.e. when files are too large or they have the wrong MIME type etc.), but this failure handling code is not shown here for clarity purposes. Please see How do I Handle File Upload Failures  for an explanation.

 

 

Please see the Putting it all together section, specifically Handling Upload Failure with and without Partial Uploads for detailed examples.

 

back to main index

top of page

 

 

 

 

 

 

© Gubutech(Xload) 2006 (v1.2)