Home > Uncategorized > File upload using REST Spring MVC

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


The web service itself is configured like this:

@RequestMapping(value = "/fileUpload", method = RequestMethod.POST)
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

  1. shantisattiraju
    December 7, 2010 at 2:59 am


    Thanks for the post.Helped a lot!!!!

  2. Don
    March 30, 2011 at 5:47 am

    Can I have your complete File upload REST service example including java codes and config files?

  3. Loïc
    March 30, 2011 at 1:26 pm

    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

  4. balayogi
    November 8, 2011 at 4:11 am

    can any one pls give me a sample program of file upload and download using spring restfull webservices

  5. java
    September 19, 2012 at 11:12 am

    can you give an example to upload multiple file upload thriugh annotation @requestparam

    • Loïc
      September 19, 2012 at 2:40 pm

      hi java,
      excellent question. I have cloned spring-mvc-showcase on github and added a controller + a jsp. It works fine just by adding brackets after MultipartFile.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: