Announcement Announcement Module
Collapse
No announcement yet.
image file upload issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Read this:

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

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

    Comment


    • #3
      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."

      Comment


      • #4
        Do you have commons fileupload in your classpath?

        Comment


        • #5
          Yes,

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

          Comment

          Working...
          X