Interface for multipart resolution strategies that handle file uploads as
defined in RFC 1867.
Implementations are typically usable both within any application context
and standalone.
There are two concrete implementations included in Spring:
CommonsMultipartResolver for Jakarta Commons FileUpload
CosMultipartResolver for Jason Hunter's COS (com.oreilly.servlet)
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 DispatcherServlet.
If a DispatcherServlet detects a multipart request, it will resolve it
via the configured MultipartResolver and pass on a wrapped HttpServletRequest.
Controllers can then cast their given request to the MultipartHttpServletRequest
interface, being able to access MultipartFiles. Note that this cast is only
supported in case of an actual multipart request.
Instead of direct access, command or form controllers can register a
ByteArrayMultipartFileEditor or StringMultipartFileEditor with their data
binder, to automatically apply multipart content to command bean properties.
As an alternative to using a MultipartResolver with a DispatcherServlet,
a 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.
There are two concrete implementations included in Spring:
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 DispatcherServlet.
If a DispatcherServlet detects a multipart request, it will resolve it via the configured MultipartResolver and pass on a wrapped HttpServletRequest. Controllers can then cast their given request to the MultipartHttpServletRequest interface, being able to access MultipartFiles. Note that this cast is only supported in case of an actual multipart request.
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 ByteArrayMultipartFileEditor or StringMultipartFileEditor with their data binder, to automatically apply multipart content to command bean properties.As an alternative to using a MultipartResolver with a DispatcherServlet, a 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.