image file upload issue
I am working on uploading the image files in spring using the multipart file approach and i am not able to get through it successfully. I use CommonsMultipartResolver.
My POJO has these properties with accessor methods.
My bean definition for CommonsMultipartResolver is as follows
private MultipartFile imageFile;
private MultipartFile thumbnailFile;
My view has the following defined.
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
But i keep getting this error.
<form:form id="form" name="form1" commandName="campaign" method="post"
Image : </label> <input name="thumbnailFile" id="thumbnailFile" type="file" />
<form:errors path="thumbnailFile" /> <br />
<label>Item Image : </label> <input name="imageFile" type="file"
id="itemImage" /> <form:errors path="imageFile" /> <br />
Failed to convert property value of type java.lang.String to required type org.springframework.web.multipart.MultipartFile for property thumbnailFile; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property thumbnailFile: no matching editors or conversion strategy found
I am really confused if i am missing anything.
You need to register a custom binder in your controller. Did you do that?
The document does not say that we need to register any custom binder for MultipartFile.
"The third (and final) option is where one binds directly to a MultipartFile property declared on the (form backing) object's class. In this case one does not need to register any custom PropertyEditor because there is no type conversion to be performed."
Do you have commons fileupload in your classpath?