Results 1 to 5 of 5

Thread: image file upload issue

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    28

    Unhappy image file upload issue

    Hi All,

    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.
    Code:
    	private MultipartFile imageFile;
    
    	private MultipartFile thumbnailFile;
    My bean definition for CommonsMultipartResolver is as follows
    Code:
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
    My view has the following defined.

    Code:
    <form:form id="form" name="form1" commandName="campaign" method="post"
    	action="savecampaign.html" enctype="multipart/form-data">
    	<legend>Images</legend><label>Thumbnail
    	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 />
    </form:form>
    But i keep getting this error.

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Read this:

    http://static.springsource.org/sprin...#mvc-multipart

    You need to register a custom binder in your controller. Did you do that?

  3. #3
    Join Date
    Feb 2008
    Posts
    28

    Default

    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."

  4. #4
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Do you have commons fileupload in your classpath?

  5. #5
    Join Date
    Feb 2008
    Posts
    28

    Default

    Yes,

    Code:
    <dependency>
    	<groupId>commons-fileupload</groupId>
    	<artifactId>commons-fileupload</artifactId>
    	<version>1.1.1</version>
    </dependency>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •