File upload using REST Spring MVC
A quick note on developing an HTTP POST based web service using Spring 3 MVC and its testing using curl command line program.
To me the most important resides in the configuration file:
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="300000"/><!-- Max size in bytes. -->
</bean>
The web service itself is configured like this:
@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
@ResponseBody
public myObject upload (
@RequestParam("file") MultipartFile multipartFile,
HttpServletRequest request) {...
and the curl command is:
curl -F "file=@file.jpg" http://localhost:8080/fileUpload
Edit 4/12/2011: just noticed there exists a nice working example at springsource dealing with this (and much more), here

Hi,
Thanks for the post.Helped a lot!!!!
Can I have your complete File upload REST service example including java codes and config files?
@Don
I did this inside a larger project owned by my company. However, yes, I’ll try to upload an example in a separate project, but not sure when
can any one pls give me a sample program of file upload and download using spring restfull webservices
Hi balayogi,
for an upload sample download spring mvc sample and deploy it on your server. As the code shows the url you be sthg like: http://localhost:8080/spring-mvc-showcase/fileupload for file upload.
Once uploaded you need to move the file ideally on a public repository of your http server (e.g. apache). So it depends on your configuration for the download. Once moved on a public repository you should be able to download by simply doing a “GET” on the repository name+ name of file (e.g. http://localhost/public/myfile.xls)
Loic