Close

Spring MVC - Understanding MultipartResolver

[Last Updated: May 29, 2026]

Spring uses strategy interface MultipartResolver for multipart file upload resolution.

Definition of MultipartResolver

Version: 7.0.6
 package org.springframework.web.multipart;
 public interface MultipartResolver {
     boolean isMultipart(HttpServletRequest request); 1
     MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
                                         throws MultipartException; 2
     void cleanupMultipart(MultipartHttpServletRequest request); 3
 }
1Determine if the given request contains multipart content.
2Parse the given HTTP request into multipart files and parameters, and wrap the request inside a org.springframework.web.multipart.MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.
3Clean up any resources used for the multipart handling, like a storage for the uploaded files.

DispatcherServlet looks for an instance of MultipartResolver registered as a bean by the name of DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME ("multipartResolver"). No default bean is registered. That means, to enable file uploading, the application has to register an implementation of MultipartResolver.

The DispatcherServlet.doDispatch() method checks if the request is for file upload by calling MultipartResolver.isMultipart(). This method returns true if the request is typically a POST request with the content-type of "multipart/form-data". On passing this check, the method MultipartResolver#resolveMultipart() is called which parses the given HTTP request into multipart files and parameters, and wraps the request inside a MultipartHttpServletRequest object that provides access to the uploaded file info/content. At his point the file contents are already stored in memory or in a temp folder unless the MultipartResolver implementation chooses to do so lazily.

At the end of request processing in DispatcherServlet.doDispatch() method (in the finally block), MultipartResolver.cleanupMultipart() is called so that underlying implementation can cleanup any resources used for the multipart handling, like a storage for the uploaded files.

MultipartResolver implementations

Prior to Spring 5.0, the framework shipped with two distinct MultipartResolver implementations, giving developers a choice of parsing strategy.

Pre Spring 5: Two Resolver Implementations

1. CommonsMultipartResolver
Based on the third‑party Apache Commons FileUpload library. This resolver handled multipart request parsing entirely within the application, without depending on the servlet container’s built‑in support. It required the commons-fileupload jar on the classpath and used javax.servlet types.

2. StandardServletMultipartResolver
Introduced to leverage the native multipart parsing provided by Servlet 3.0+ containers. It relied on the javax.servlet.http.Part API and required container‑level configuration (e.g. @MultipartConfig or a multipart-config element in web.xml).

Both resolvers lived in the org.springframework.web.multipart package and were configured as a bean named multipartResolver.

Spring 5: Deprecation of CommonsMultipartResolver

Starting with Spring Framework 5.0, CommonsMultipartResolver was officially deprecated. The Spring team recommended migrating to the standard container‑based StandardServletMultipartResolver. The primary reasons were:

  • All modern servlet containers already provided robust multipart handling.
  • Removing the third‑party dependency reduced the maintenance burden and eliminated a common source of classloading issues.
  • The standard API (javax.servlet.http.Part) offered a cleaner, more portable programming model.

Spring 6: Complete Removal of CommonsMultipartResolver

The deprecated class CommonsMultipartResolver was fully removed. The only available implementation is StandardServletMultipartResolver, which must be used exclusively.

The controller

MultipartHttpServletRequest.getFile('fileName') and other methods can be used in our controller to access the uploaded file info/content:

@PostMapping("/form")
 public String handleRequest(HttpServletRequest request, ...) {
    MultipartHttpServletRequest multipartRequest = 
                                   (MultipartHttpServletRequest) request;
    MultipartFile multipartFile = multipartRequest.getFile("user-file");
    ...
  }

Using MultipartHttpServletRequest

MultipartFile is an interface which represents the uploaded file received in the multipart request.

We can also use MultipartHttpServletRequest as handler method parameter

public String handlePostRequest (MultipartHttpServletRequest request, ...)  {
   MultipartFile multipartFile = request.getFile("user-file");
    ......
   return "response";
}

Using MultipartFile

We can also use MultipartFile as handler method parameter. MultipartFile is a Spring specific representation of an uploaded file received in a multipart request.

@PostMapping("/form")
  public String handleUpload(@RequestParam("user-file") MultipartFile file, ...) {

        if (!file.isEmpty()) {
            byte[] bytes = file.getBytes();
            // do something with the content
            ...
        }
      ....
    }

Using javax.servlet.http.Part

When using StandardServletMultipartResolver, we can also use javax.servlet.http.Part as a method parameter instead of Spring's MultipartFile.

@PostMapping("/form")
  public String handleUpload(@RequestParam("user-file") 
                               javax.servlet.http.Part part, ...) {
     InputStream inputStream = part.getInputStream();
      ....
    }

In next tutorials, we will see complete examples on how to use file uploads in Spring.

See Also

Join