You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andrew Moore <an...@bigfoot.com> on 2008/08/18 14:25:11 UTC

Using FileUpload.writeTo() in a background thread

I'm doing a file uploading screen, where some of the files can be quite large
(up to 30mb) and am therefore hoping to be able to process the actual upload
in a separate thread to the screen.

All my post processing on the file that takes place works fine in a separate
thread, but if I try to do the writing of the file with a
FileUpload.writeTo() I get an IO exception that the file handle is invalid.

Is what I'm trying to do possible? I'm guessing that the file handle is
getting closed or lost as the upload page finishes.

If it's not possible with the writeTo method, is there any other way of
doing this?
See example below.
Thanks
Andrew

Example: OnSubmit (ie upload button)
=============================
public void onSubmit() {
     final FileUpload upload = uploadField.getFileUpload();

     if (upload != null){
	File newFile = new File(uploadFolder, upload.getClientFileName());
	
	// create the new file
	newFile.createNewFile();
	
	/* works if "uploadFile.writeTo(newFile);" is done here */
	
	final ImportThread it = new ImportThread(getMySession(), upload,
uploadFolder, newFile);
	it.start();
     }
}



Separate thread:
============
private static class ImportThread extends Thread {
	private final SignInSession session;
	private final FileUpload uploadFile;
	private final Folder uploadFolderThread;
	private File newFile;


	public ImportThread(SignInSession session, FileUpload uploadFile, Folder
uploadFolderThread, File newFile) {
		logger.debug("long running thread constructor");
		this.session = session;
		this.uploadFile = uploadFile;
		this.uploadFolderThread = uploadFolderThread;
		this.newFile = newFile;
		this.filename = filename;
	}

	public void run() {
			
		logger.debug("long running thread run");
	        uploadFile.writeTo(newFile);          /* causes invalid file handle
when run in thread */
	        //other post processing here....
        }				
}
-- 
View this message in context: http://www.nabble.com/Using-FileUpload.writeTo%28%29-in-a-background-thread-tp19030588p19030588.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org