Tuesday, September 06, 2005

Upload file in Struts: need for commons fileupload?

Actually I found out that there is no need, after sometime trying to make the commons fileupload work. Check a post from jakarta-commons-user list explaining it:

"The request stream for a multipart/form-data can only be read once - by the time Struts decides what Action to execute, goes through setting up the Form and validating, it's actually already read the request. Use a formBean that has accessors/mutators for org.apache.struts.upload.FormFile's, and pass the formBean to your action.

See the struts-upload webapp for a very good example.

The short answer is - you don't HAVE to do all the junk below when you're using Struts - the smart developers for Struts did all that junk for you so you can just use your file directly."
Post a Comment