public interface PortletMultipartResolver
Implementations are typically usable both within any application context and standalone.
There is one concrete implementation included in Spring:
CommonsMultipartResolver
for Apache Commons FileUploadThere is no default resolver implementation used for Spring DispatcherPortlets
, as an application might choose to parse its multipart requests itself. To define an
implementation, create a bean with the id "portletMultipartResolver" in a DispatcherPortlet's
application
context. Such a resolver gets applied to all requests handled by that DispatcherPortlet
.
If a DispatcherPortlet
detects a multipart request, it will resolve it via the configured PortletMultipartResolver
and pass on a wrapped Portlet ActionRequest
. Controllers can then cast their given request to the MultipartActionRequest
interface, being
able to access MultipartFiles
. Note that this cast is only supported in case of an actual multipart request.
public void handleActionRequest(ActionRequest request, ActionResponse response) { MultipartActionRequest multipartRequest = (MultipartActionRequest) 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 form bean properties.
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 MultipartActionRequests
available to controllers.
MultipartActionRequest
,
MultipartResourceRequest
,
MultipartFile
,
CommonsPortletMultipartResolver
,
ByteArrayMultipartFileEditor
,
StringMultipartFileEditor
,
DispatcherPortlet
Modifier and Type | Method and Description |
---|---|
void |
cleanupMultipart(MultipartActionRequest request)
Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).
|
void |
cleanupMultipart(MultipartResourceRequest request)
Cleanup any resources used for the multipart handling, such as storage for any uploaded file(s).
|
boolean |
isMultipart(javax.portlet.ActionRequest request)
Determine if the given request contains multipart content.
|
boolean |
isMultipart(javax.portlet.ResourceRequest request)
Determine if the given request contains multipart content.
|
MultipartActionRequest |
resolveMultipart(javax.portlet.ActionRequest request)
Parse the given portlet request into multipart files and parameters, and wrap the request inside a
MultipartActionRequest object that provides access to file descriptors and makes contained parameters accessible
via the standard PortletRequest methods.
|
MultipartResourceRequest |
resolveMultipart(javax.portlet.ResourceRequest request)
Parse the given portlet request into multipart files and parameters, and wrap the request inside a
MultipartResourceRequest object that provides access to file descriptors and makes contained parameters
accessible via the standard PortletRequest methods.
|
void cleanupMultipart(MultipartActionRequest request)
request
- the request to cleanup resources forvoid cleanupMultipart(MultipartResourceRequest request)
request
- the request to cleanup resources forboolean isMultipart(javax.portlet.ActionRequest request)
Will typically check for content type"multipart/form-data
", but the actually accepted requests might
depend on the capabilities of the resolver implementation.
request
- the portlet request to be evaluatedboolean isMultipart(javax.portlet.ResourceRequest request)
Will typically check for content type"multipart/form-data
", but the actually accepted requests might
depend on the capabilities of the resolver implementation.
request
- the portlet request to be evaluatedMultipartActionRequest resolveMultipart(javax.portlet.ActionRequest request) throws MultipartException
request
- the portlet request to wrap (must be of a multipart content type)MultipartException
- if the portlet request is not multipart, or if
implementation-specific problems are encountered
(such as exceeding file size limits)MultipartRequest.getFile(java.lang.String)
,
MultipartRequest.getFileNames()
,
MultipartRequest.getFileMap()
,
PortletRequest.getParameter(java.lang.String)
,
PortletRequest.getParameterNames()
,
PortletRequest.getParameterMap()
MultipartResourceRequest resolveMultipart(javax.portlet.ResourceRequest request) throws MultipartException
request
- the portlet request to wrap (must be of a multipart content type)MultipartException
- if the portlet request is not multipart, or if
implementation-specific problems are encountered
(such as exceeding file size limits)MultipartRequest.getFile(java.lang.String)
,
MultipartRequest.getFileNames()
,
MultipartRequest.getFileMap()
,
PortletRequest.getParameter(java.lang.String)
,
PortletRequest.getParameterNames()
,
PortletRequest.getParameterMap()
Copyright © 2019 Liferay, Inc.. All rights reserved.