25) Looking at File Renaming |
In the following example three files are uploaded, all MIME types are allowed but blank file fields are not. The code determines whether or not a successful file upload has been renamed and reports this. Failed uploads are also reported on. The variety of information that can be drawn from the results of an upload by Xload is very varied and extensive, producing a fine grained report if required, or a simple message if that is all that is needed.
XloadManager xman = new XloadManager(request); xman.target("file1", "uploaded", 4096); xman.target("file2", "uploaded", 4096); xman.target("file3", "uploaded", 4096); xman.upload();
//deal with any failed StringBuffer error = new StringBuffer(100); List failed = xman.getFailedFileUploads(); it = failed.iterator(); while(it.hasMore()){ upload = (XloadFileUpload)it.next(); String param = upload.getRequestParameter(); error.append(param + " failed to upload due to:" + //list possible reasons or give generic //message. "\n"); }
//handle successful uploads StringBuffer renamed = new StringBuffer(100); List successful = xman.getSuccessfulFileUploads(); XloadFileUpload upload = null; Iterator it = successful.iterator(); while(it.hasMore()){ upload = (XloadFileUpload)it.next(); String param = upload.getRequestParameter(); XloadFile file = upload.getFile(1); if(file.isRenamed()){ renamed.append(param + "has been renamed "+ "to: "+ file.getWrittenName() + "\n"; } //now, backup uploaded file to another directory using //a different name. file.resetTargetName(file.getWrittenName()+ "backup"); file.copyTo("uploadedbackup"); //place file details inside relational database. }
//return a response using the error object and the renamed //object to create a report(renamed and upload failures).
|
© Gubutech(Xload) 2006 (v1.2)