Top Description Methods
org.springframework.web.multipart

public Interface MultipartResolver

Known Direct Implementers
org.springframework.web.multipart.support.StandardServletMultipartResolver
Imports
jakarta.servlet.http.HttpServletRequest

A strategy interface for multipart file upload resolution in accordance with RFC 1867. Implementations are typically usable both within an application context and standalone.

Spring provides the following concrete implementation:

There is no default resolver implementation used for Spring DispatcherServlets, as an application might choose to parse its multipart requests itself. To define an implementation, create a bean with the id "multipartResolver" in a DispatcherServlet's application context. Such a resolver gets applied to all requests handled by that org.springframework.web.servlet.DispatcherServlet.

If a org.springframework.web.servlet.DispatcherServlet detects a multipart request, it will resolve it via the configured MultipartResolver and pass on a wrapped jakarta.servlet.http.HttpServletRequest. Controllers can then cast their given request to the MultipartHttpServletRequest interface, which allows for access to any MultipartFiles. Note that this cast is only supported in case of an actual multipart request.

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
  MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
  MultipartFile multipartFile = multipartRequest.getFile("image");
  ...
}
Instead of direct access, command or form controllers can register a org.springframework.web.multipart.support.ByteArrayMultipartFileEditor or org.springframework.web.multipart.support.StringMultipartFileEditor with their data binder, to automatically apply multipart content to form bean properties.

As an alternative to using a MultipartResolver with a org.springframework.web.servlet.DispatcherServlet, a org.springframework.web.multipart.support.MultipartFilter can be registered in web.xml. It will delegate to a corresponding MultipartResolver bean in the root application context. This is mainly intended for applications that do not use Spring's own web MVC framework.

Note

There is hardly ever a need to access the MultipartResolver itself from application code. It will simply do its work behind the scenes, making MultipartHttpServletRequests available to controllers.

Authors
Juergen Hoeller, Trevor D. Cook
Since
29.09.2003
See Also
MultipartHttpServletRequest, MultipartFile, org.springframework.web.multipart.support.ByteArrayMultipartFileEditor, org.springframework.web.multipart.support.StringMultipartFileEditor, org.springframework.web.servlet.DispatcherServlet

Method Summary

Modifier and TypeMethod and Description
public void
cleanupMultipart(MultipartHttpServletRequest
the request to clean up resources for
request
)

Clean up any resources used for the multipart handling, like a storage for the uploaded files.

public boolean

Returns:

whether the request contains multipart content
isMultipart
(HttpServletRequest
the servlet request to be evaluated
request
)

Determine if the given request contains multipart content.

public MultipartHttpServletRequest

Returns:

the wrapped servlet request
resolveMultipart
(HttpServletRequest
the servlet request to wrap (must be of a multipart content type)
request
)

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

Method Detail

cleanupMultipartback to summary
public void cleanupMultipart(MultipartHttpServletRequest request)

Clean up any resources used for the multipart handling, like a storage for the uploaded files.

Parameters
request:MultipartHttpServletRequest

the request to clean up resources for

isMultipartback to summary
public boolean isMultipart(HttpServletRequest request)

Determine if the given request contains multipart content.

Will typically check for content type "multipart/form-data", but the actually accepted requests might depend on the capabilities of the resolver implementation.

Parameters
request:HttpServletRequest

the servlet request to be evaluated

Returns:boolean

whether the request contains multipart content

resolveMultipartback to summary
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException

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

Parameters
request:HttpServletRequest

the servlet request to wrap (must be of a multipart content type)

Returns:MultipartHttpServletRequest

the wrapped servlet request

Exceptions
MultipartException:
if the servlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)
See Also
MultipartHttpServletRequest#getFile, MultipartHttpServletRequest#getFileNames, MultipartHttpServletRequest#getFileMap, jakarta.servlet.http.HttpServletRequest#getParameter, jakarta.servlet.http.HttpServletRequest#getParameterNames, jakarta.servlet.http.HttpServletRequest#getParameterMap