View Full Version : fileupload help
abstraction
Jun 3rd, 2005, 11:48 AM
I'm looking at the fileupload example and I'm having a little trouble figuring out how to process the file from within ProcessUploadAction.java. Can someone give me a brief example of how to get at the file from within ProcessUploadAction.java?
Thanks for the pointers.
klr8
Jun 3rd, 2005, 12:01 PM
Since the ProcessUploadAction puts the FileUploadBean in REQUEST scope (the default), you would do something like this:
public Event processFile(RequestContext context) throws Exception {
FileUploadBean fub=(FileUploadBean)context.getRequestScope().getA ttribute("file");
byte[] fileData=fub.getFile();
... //process file data
return success();
}
You would then need to invoke this processFile() method from an action state, something like this:
<action-state id="processFile">
<action bean="upload.process"/>
<transition on="success" to="..."/>
</action-state>
abstraction
Jun 3rd, 2005, 12:41 PM
That's exactly what I've done. The only problem is that fub ends up being null.
abstraction
Jun 3rd, 2005, 01:06 PM
This did the trick.
public Event processFile(RequestContext context) throws Exception {
bindAndValidate(context);
FileUploadBean fub=(FileUploadBean)context.getRequestScope().getA ttribute("file");
byte[] fileData=fub.getFile();
... //process file data
return success();
}
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.