public class

CommonsMultipartResolver

extends CommonsFileUploadSupport
implements ServletContextAware MultipartResolver
java.lang.Object
   ↳ org.springframework.web.multipart.commons.CommonsFileUploadSupport
     ↳ org.springframework.web.multipart.commons.CommonsMultipartResolver

Class Overview

Servlet-based MultipartResolver implementation for Jakarta Commons FileUpload 1.2 or above.

Provides "maxUploadSize", "maxInMemorySize" and "defaultEncoding" settings as bean properties (inherited from CommonsFileUploadSupport). See corresponding ServletFileUpload / DiskFileItemFactory properties ("sizeMax", "sizeThreshold", "headerEncoding") for details in terms of defaults and accepted values.

Saves temporary files to the servlet container's temporary directory. Needs to be initialized either by an application context or via the constructor that takes a ServletContext (for standalone usage).

See Also

Summary

[Expand]
Inherited Fields
From class org.springframework.web.multipart.commons.CommonsFileUploadSupport
Public Constructors
CommonsMultipartResolver()
Constructor for use as bean.
CommonsMultipartResolver(ServletContext servletContext)
Constructor for standalone usage.
Public Methods
void cleanupMultipart(MultipartHttpServletRequest request)
Cleanup any resources used for the multipart handling, like a storage for the uploaded files.
boolean isMultipart(HttpServletRequest request)
Determine if the given request contains multipart content.
MultipartHttpServletRequest resolveMultipart(HttpServletRequest request)
Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.
void setResolveLazily(boolean resolveLazily)
Set whether to resolve the multipart request lazily at the time of file or parameter access.
void setServletContext(ServletContext servletContext)
Set the ServletContext that this object runs in.
Protected Methods
String determineEncoding(HttpServletRequest request)
Determine the encoding for the given request.
FileUpload newFileUpload(FileItemFactory fileItemFactory)
Initialize the underlying org.apache.commons.fileupload.servlet.ServletFileUpload instance.
CommonsFileUploadSupport.MultipartParsingResult parseRequest(HttpServletRequest request)
Parse the given servlet request, resolving its multipart elements.
[Expand]
Inherited Methods
From class org.springframework.web.multipart.commons.CommonsFileUploadSupport
From class java.lang.Object
From interface org.springframework.web.context.ServletContextAware
From interface org.springframework.web.multipart.MultipartResolver

Public Constructors

public CommonsMultipartResolver ()

Constructor for use as bean. Determines the servlet container's temporary directory via the ServletContext passed in as through the ServletContextAware interface (typically by a WebApplicationContext).

public CommonsMultipartResolver (ServletContext servletContext)

Constructor for standalone usage. Determines the servlet container's temporary directory via the given ServletContext.

Parameters
servletContext the ServletContext to use

Public Methods

public void cleanupMultipart (MultipartHttpServletRequest request)

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

Parameters
request the request to cleanup resources for

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 the servlet request to be evaluated
Returns
  • whether the request contains multipart content

public MultipartHttpServletRequest resolveMultipart (HttpServletRequest request)

Parse the given HTTP request into multipart files and parameters, and wrap the request inside a MultipartHttpServletRequest object that provides access to file descriptors and makes contained parameters accessible via the standard ServletRequest methods.

Parameters
request the servlet request to wrap (must be of a multipart content type)
Returns
  • the wrapped servlet request

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(HttpServletRequest) call. Switch this to "true" for lazy multipart parsing, throwing parse exceptions once the application attempts to obtain multipart files or parameters.

public void setServletContext (ServletContext servletContext)

Set the ServletContext that this object runs in.

Invoked after population of normal bean properties but before an init callback like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ApplicationContextAware's setApplicationContext.

Parameters
servletContext ServletContext object to be used by this object

Protected Methods

protected String determineEncoding (HttpServletRequest request)

Determine the encoding for the given request. Can be overridden in subclasses.

The default implementation checks the request encoding, falling back to the default encoding specified for this resolver.

Parameters
request current HTTP request
Returns
  • the encoding for the request (never null)

protected FileUpload newFileUpload (FileItemFactory fileItemFactory)

Initialize the underlying org.apache.commons.fileupload.servlet.ServletFileUpload instance. Can be overridden to use a custom subclass, e.g. for testing purposes.

Parameters
fileItemFactory the Commons FileItemFactory to use
Returns
  • the new ServletFileUpload instance

protected CommonsFileUploadSupport.MultipartParsingResult parseRequest (HttpServletRequest request)

Parse the given servlet request, resolving its multipart elements.

Parameters
request the request to parse
Returns
  • the parsing result
Throws
MultipartException if multipart resolution failed.