This code is a RestEasy code for handling upload:
@Path("/fileupload")
public class UploadService {
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Response create(@MultipartForm FileUploadForm form)
{
// Handle form
}
}
Is there anything similar using Spring that can handle MultipartForm
just like this?
Spring includes has a multipartresolver that relies on commons-fileupload, so to use it you have to include it in your build.
In your applicationContext.xml
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="<max file size>"/>
</bean>
In your controller, use org.springframework.web.multipart.MultipartFile.
@RequestMapping(method=RequestMethod.POST, value="/multipartexample")
public String examplePost(@RequestParam("fileUpload") MultipartFile file){
// Handle form upload and return a view
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With