dimanche 19 avril 2015

Uploading image using Spring, commons-file upload

I'm trying to upload an image following this and this tutorial but without using maven.


Here is my config related to upload:


ApplicationContext.xml



..
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10000000">
</property></bean>


My form:



<form:form
action="${ contextPath }admin/add-product"
method="POST" modelAttribute="addInventoryItemDto"
enctype="multipart/form-data">
<table>
....
<tr>
<td><b>Image:</b></td>
<td><input type="file" name="image" /></td>
</tr>
....


Controller



@RequestMapping( value = "/add-product", method = RequestMethod.POST )
public String addProduct(
@ModelAttribute( "addInventoryItemDto" ) @Valid AddInventoryItemDto inventoryDto,
@RequestParam( "image" ) MultipartFile img ) {
System.out.println("ContentType:" + img.getContentType());
return "admin/add-product";
}


I'm getting 404 Bad Request but when I remove the file related stuff in my Controller and form the request is properly sent to my controller


What I'm I missing or did wrong?


Aucun commentaire:

Enregistrer un commentaire