Top Description Fields Constructors Methods
org.springframework.web.multipart.support

public Class StandardServletMultipartResolver

extends Object
implements MultipartResolver
Class Inheritance
All Implemented Interfaces
org.springframework.web.multipart.MultipartResolver
Imports
jakarta.servlet.http.HttpServletRequest, .Part, org.apache.commons.logging.LogFactory, org.springframework.http.MediaType, org.springframework.util.StringUtils, org.springframework.web.multipart.MultipartException, .MultipartHttpServletRequest, .MultipartResolver

Standard implementation of the MultipartResolver interface, based on the Servlet jakarta.servlet.http.Part API. To be added as "multipartResolver" bean to a Spring DispatcherServlet context, without any extra configuration at the bean level (see below).

This resolver variant uses your Servlet container's multipart parser as-is, potentially exposing the application to container implementation differences. Also, see this resolver's configuration option for strict Servlet compliance, narrowing the applicability of Spring's MultipartHttpServletRequest to form data only.

Note

In order to use Servlet container based multipart parsing, you need to mark the affected servlet with a "multipart-config" section in web.xml, or with a jakarta.servlet.MultipartConfigElement in programmatic servlet registration, or (in case of a custom servlet class) possibly with a jakarta.servlet.annotation.MultipartConfig annotation on your servlet class. Configuration settings such as maximum sizes or storage locations need to be applied at that servlet registration level; a Servlet container does not allow for them to be set at the MultipartResolver level.

public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  // ...
  @Override
  protected void customizeRegistration(ServletRegistration.Dynamic registration) {
    // Optionally also set maxFileSize, maxRequestSize, fileSizeThreshold
    registration.setMultipartConfig(new MultipartConfigElement("/tmp"));
  }
}
Author
Juergen Hoeller
Since
3.1
See Also
setResolveLazily, setStrictServletCompliance, HttpServletRequest#getParts()

Field Summary

Modifier and TypeField and Description
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

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

Implements org.springframework.web.multipart.MultipartResolver.cleanupMultipart.

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

public boolean
isMultipart(HttpServletRequest
the servlet request to be evaluated
request
)

Implements org.springframework.web.multipart.MultipartResolver.isMultipart.

Determine if the given request contains multipart content.

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

Implements org.springframework.web.multipart.MultipartResolver.resolveMultipart.

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.

public void
setResolveLazily(boolean resolveLazily)

Set whether to resolve the multipart request lazily at the time of file or parameter access.

public void
setStrictServletCompliance(boolean strictServletCompliance)

Specify whether this resolver should strictly comply with the Servlet specification, only kicking in for "multipart/form-data" requests.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resolveLazilyback to summary
private boolean resolveLazily
strictServletComplianceback to summary
private boolean strictServletCompliance

Constructor Detail

StandardServletMultipartResolverback to summary
public StandardServletMultipartResolver()

Method Detail

cleanupMultipartback to summary
public void cleanupMultipart(MultipartHttpServletRequest request)

Implements org.springframework.web.multipart.MultipartResolver.cleanupMultipart.

Doc from org.springframework.web.multipart.MultipartResolver.cleanupMultipart.

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

Annotations
@Override
isMultipartback to summary
public boolean isMultipart(HttpServletRequest request)

Implements org.springframework.web.multipart.MultipartResolver.isMultipart.

Doc from org.springframework.web.multipart.MultipartResolver.isMultipart.

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

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

Implements org.springframework.web.multipart.MultipartResolver.resolveMultipart.

Doc from org.springframework.web.multipart.MultipartResolver.resolveMultipart.

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

Annotations
@Override
Exceptions
MultipartException:
if the servlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)
setResolveLazilyback to summary
public void setResolveLazily(boolean resolveLazily)

Set whether to resolve the multipart request lazily at the time of file or parameter access.

Default is "false", resolving the multipart elements immediately, throwing corresponding exceptions at the time of the resolveMultipart call. Switch this to "true" for lazy multipart parsing, throwing parse exceptions once the application attempts to obtain multipart files or parameters.

Since
3.2.9
setStrictServletComplianceback to summary
public void setStrictServletCompliance(boolean strictServletCompliance)

Specify whether this resolver should strictly comply with the Servlet specification, only kicking in for "multipart/form-data" requests.

Default is "false", trying to process any request with a "multipart/" content type as far as the underlying Servlet container supports it (which works on e.g. Tomcat but not on Jetty). For consistent portability and in particular for consistent custom handling of non-form multipart request types outside of Spring's MultipartResolver mechanism, switch this flag to "true": Only "multipart/form-data" requests will be wrapped with a MultipartHttpServletRequest then; other kinds of requests will be left as-is, allowing for custom processing in user code.

Since
5.3.9