Discussion:
multiple file uploads with one property
Durham David R Jr Ctr 805 CSPTS/SCE
2005-05-05 16:15:41 UTC
Permalink
Tried using a property like this:

<form-bean name="..."
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="files"
type="org.apache.struts.upload.FormFile[]"/>
</form-bean>

But I get the following class cast exception:

org.apache.commons.beanutils.ConversionException: Cannot assign value of
type
rg.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile'
to property 'files' of type '[org.apache.struts.upload.FormFile;'

org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:424)

org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(Propert
yUtilsBean.java:1733)

org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(Propert
yUtilsBean.java:1648)

org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtils
Bean.java:1677)

org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.jav
a:1022)

org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:8
11)

org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)

org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)

org.apache.struts.action.RequestProcessor.processPopulate(RequestProcess
or.java:798)

...

Any ideas what is happening? It works if I take out the '[]'.


Thanks,

Dave
Durham David R Jr Ctr 805 CSPTS/SCE
2005-05-05 18:35:32 UTC
Permalink
Upon further investigation, it appears that commons-fileupload does not
support uploading multiple files with the same parameter name. I'm
going to take this discussion (with myself) over to commons list.


- Dave
-----Original Message-----
From: Durham David R Jr Ctr 805 CSPTS/SCE
Sent: Thursday, May 05, 2005 11:16 AM
To: Struts Users Mailing List
Subject: multiple file uploads with one property
<form-bean name="..."
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="files"
type="org.apache.struts.upload.FormFile[]"/>
</form-bean>
org.apache.commons.beanutils.ConversionException: Cannot assign value
of
type
rg.apache.struts.upload.CommonsMultipartRequestHandler$CommonsFormFile'
to property 'files' of type '[org.apache.struts.upload.FormFile;'
org.apache.struts.action.DynaActionForm.set(DynaActionForm.java:424)
org.apache.commons.beanutils.PropertyUtilsBean.setSimpleProperty(Propert
yUtilsBean.java:1733)
org.apache.commons.beanutils.PropertyUtilsBean.setNestedProperty(Propert
yUtilsBean.java:1648)
org.apache.commons.beanutils.PropertyUtilsBean.setProperty(PropertyUtils
Bean.java:1677)
org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.jav
a:1022)
org.apache.commons.beanutils.BeanUtilsBean.populate(BeanUtilsBean.java:8
11)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:298)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcess
or.java:798)
...
Any ideas what is happening? It works if I take out the '[]'.
Thanks,
Dave
---------------------------------------------------------------------
Niall Pemberton
2005-05-05 21:08:07 UTC
Permalink
Apologies, I'm not an expert in FileUpload. However I believe the Commons
FileUpload will handle multiple files - since what it does is basically
parse the request and return a list of items. I think the issue is probably
in Struts. There are these tickets related to this:

http://issues.apache.org/bugzilla/show_bug.cgi?id=6847
http://issues.apache.org/bugzilla/show_bug.cgi?id=25963
http://issues.apache.org/bugzilla/show_bug.cgi?id=29807

I would suggest starting by looking at the Struts
CommonsMultipartRequestHandler class to see how it uses Commons FileUpload.
The other place to look is in how Struts takes the file items and populates
them in the ActionForm which is in RequestUtil's populate method.

Niall

----- Original Message -----
From: "Durham David R Jr Ctr 805 CSPTS/SCE" <***@scott.af.mil>
Sent: Thursday, May 05, 2005 7:35 PM


Upon further investigation, it appears that commons-fileupload does not
support uploading multiple files with the same parameter name. I'm
going to take this discussion (with myself) over to commons list.
Durham David R Jr Ctr 805 CSPTS/SCE
2005-05-05 21:48:23 UTC
Permalink
Post by Niall Pemberton
http://issues.apache.org/bugzilla/show_bug.cgi?id=6847
http://issues.apache.org/bugzilla/show_bug.cgi?id=25963
http://issues.apache.org/bugzilla/show_bug.cgi?id=29807
Hmm, yeah ok, I'll look at these. It would be nice if this were fixed
before 1.2.7. What are the chances?


- Dave
Durham David R Jr Ctr 805 CSPTS/SCE
2005-05-06 19:16:16 UTC
Permalink
Post by Niall Pemberton
http://issues.apache.org/bugzilla/show_bug.cgi?id=25963
I applied the suggested patch, and tested it. Looks like it works,
though I'm not exactly sure what an automated test script would like for
this use case. BTW, does anyone else find the ASCII art in this test
hilarious?

http://tinyurl.com/c4dro (MultipartBoundaryInputStreamTest)


Thanks,

Dave

Loading...