3. Handling upload failure specifically, giving the user fine grained results as to why uploads have failed. NO partial uploads allowed.

 

back to examples

 

All MIME types are being allowed as is an empty field for a file parameter. The code informs the user of any failure to upload any file and it gives the user detailed reasons for each upload failure. As can be seen it is a relatively small piece of code to achieve these fine grained results.

 

 

 

XloadManager xman = new XloadManager(request);

xman.target("file1", "uploaded1", 4096);

xman.target("file2", "uploaded2", 4096);

xman.target("file3", "uploaded3", 4096);

xman.upload();

 

//handle successful uploads first

List successful = xman.getSuccessfulFileUploads();

XloadFileUpload upload = null;

Iterator it = successful.iterator();

while(it.hasMore()){

upload = (XloadFileUpload)it.next();

XloadFile file = upload.getFile(1);

//place file details inside relational database

}

 

//deal with failed

int fieldBlank = 0;

StringBuffer error = new StringBuffer(100);

List failed = xman.getFailedFileUploads();

it = failed.iterator();

while(it.hasMore()){

upload = (XloadFileUpload)it.next();

String param = upload.getRequestParameter();

switch(upload.getFailureCode()){

case 1:

fieldBlank++;

break;

case 2:

error.append(param + " cannot be uploaded because "+

"the path given does not represent a file.\n");

break;

case 4:

error.append(param + " cannot be uploaded because " +

"the file is too large(4Mb max).\n");

break;

default:

error.append("There has been a problem uploading " +

param + "\n");

//please note that case 3: will not occur as we are allowing all

//MIME types and case 5: will not occur because we are not

//allowing partial uploads.

}

}

 

if(fieldBlank == 3){

//return a response displaying that there have been

//no files uploaded as all file fields are blank.

}

//return a response using the error object as an error message

//(i.e. some uploads have failed).

 

 

 

 

back to examples

 

 

 

© Gubutech(Xload) 2006 (v1.2)