|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.multipart.commons.CommonsFileUploadSupport
public abstract class CommonsFileUploadSupport
Base class for multipart resolvers that use Jakarta Commons FileUpload 1.2 or above.
Provides common configuration properties and parsing functionality for multipart requests, using a Map of Spring CommonsMultipartFile instances as representation of uploaded files and a String-based parameter Map as representation of uploaded form fields.
Subclasses implement concrete resolution strategies for Servlet or Portlet environments: see CommonsMultipartResolver and CommonsPortletMultipartResolver, respectively. This base class is not tied to either of those APIs, factoring out common functionality.
CommonsMultipartFile
,
CommonsMultipartResolver
,
CommonsPortletMultipartResolver
Nested Class Summary | |
---|---|
protected static class |
CommonsFileUploadSupport.MultipartParsingResult
Holder for a Map of Spring MultipartFiles and a Map of multipart parameters. |
Field Summary | |
---|---|
private DiskFileItemFactory |
fileItemFactory
|
private FileUpload |
fileUpload
|
protected Log |
logger
|
private boolean |
uploadTempDirSpecified
|
Constructor Summary | |
---|---|
CommonsFileUploadSupport()
Instantiate a new CommonsFileUploadSupport with its corresponding FileItemFactory and FileUpload instances. |
Method Summary | |
---|---|
protected void |
cleanupFileItems(MultiValueMap<java.lang.String,MultipartFile> multipartFiles)
Cleanup the Spring MultipartFiles created during multipart parsing, potentially holding temporary data on disk. |
private java.lang.String |
determineEncoding(java.lang.String contentTypeHeader,
java.lang.String defaultEncoding)
|
protected java.lang.String |
getDefaultEncoding()
|
DiskFileItemFactory |
getFileItemFactory()
Return the underlying org.apache.commons.fileupload.disk.DiskFileItemFactory
instance. |
FileUpload |
getFileUpload()
Return the underlying org.apache.commons.fileupload.FileUpload
instance. |
protected boolean |
isUploadTempDirSpecified()
|
protected DiskFileItemFactory |
newFileItemFactory()
Factory method for a Commons DiskFileItemFactory instance. |
protected abstract FileUpload |
newFileUpload(FileItemFactory fileItemFactory)
Factory method for a Commons FileUpload instance. |
protected CommonsFileUploadSupport.MultipartParsingResult |
parseFileItems(java.util.List<FileItem> fileItems,
java.lang.String encoding)
Parse the given List of Commons FileItems into a Spring MultipartParsingResult, containing Spring MultipartFile instances and a Map of multipart parameter. |
protected FileUpload |
prepareFileUpload(java.lang.String encoding)
Determine an appropriate FileUpload instance for the given encoding. |
void |
setDefaultEncoding(java.lang.String defaultEncoding)
Set the default character encoding to use for parsing requests, to be applied to headers of individual parts and to form fields. |
void |
setMaxInMemorySize(int maxInMemorySize)
Set the maximum allowed size (in bytes) before uploads are written to disk. |
void |
setMaxUploadSize(long maxUploadSize)
Set the maximum allowed size (in bytes) before uploads are refused. |
void |
setUploadTempDir(Resource uploadTempDir)
Set the temporary directory where uploaded files get stored. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final Log logger
private final DiskFileItemFactory fileItemFactory
private final FileUpload fileUpload
private boolean uploadTempDirSpecified
Constructor Detail |
---|
public CommonsFileUploadSupport()
newFileItemFactory()
,
newFileUpload(FileItemFactory)
Method Detail |
---|
public DiskFileItemFactory getFileItemFactory()
org.apache.commons.fileupload.disk.DiskFileItemFactory
instance. There is hardly any need to access this.
public FileUpload getFileUpload()
org.apache.commons.fileupload.FileUpload
instance. There is hardly any need to access this.
public void setMaxUploadSize(long maxUploadSize)
maxUploadSize
- the maximum upload size allowedorg.apache.commons.fileupload.FileUploadBase#setSizeMax
public void setMaxInMemorySize(int maxInMemorySize)
maxInMemorySize
- the maximum in memory size allowedorg.apache.commons.fileupload.disk.DiskFileItemFactory#setSizeThreshold
public void setDefaultEncoding(java.lang.String defaultEncoding)
If the request specifies a character encoding itself, the request
encoding will override this setting. This also allows for generically
overriding the character encoding in a filter that invokes the
ServletRequest.setCharacterEncoding
method.
defaultEncoding
- the character encoding to usejavax.servlet.ServletRequest#getCharacterEncoding
,
javax.servlet.ServletRequest#setCharacterEncoding
,
WebUtils.DEFAULT_CHARACTER_ENCODING
,
org.apache.commons.fileupload.FileUploadBase#setHeaderEncoding
protected java.lang.String getDefaultEncoding()
public void setUploadTempDir(Resource uploadTempDir) throws java.io.IOException
java.io.IOException
WebUtils.TEMP_DIR_CONTEXT_ATTRIBUTE
protected boolean isUploadTempDirSpecified()
protected DiskFileItemFactory newFileItemFactory()
Default implementation returns a standard DiskFileItemFactory. Can be overridden to use a custom subclass, e.g. for testing purposes.
protected abstract FileUpload newFileUpload(FileItemFactory fileItemFactory)
To be implemented by subclasses.
fileItemFactory
- the Commons FileItemFactory to build upon
protected FileUpload prepareFileUpload(java.lang.String encoding)
Default implementation returns the shared FileUpload instance if the encoding matches, else creates a new FileUpload instance with the same configuration other than the desired encoding.
encoding
- the character encoding to use
protected CommonsFileUploadSupport.MultipartParsingResult parseFileItems(java.util.List<FileItem> fileItems, java.lang.String encoding)
fileItems
- the Commons FileIterms to parseencoding
- the encoding to use for form fields
CommonsMultipartFile#CommonsMultipartFile(org.apache.commons.fileupload.FileItem)
protected void cleanupFileItems(MultiValueMap<java.lang.String,MultipartFile> multipartFiles)
Deletes the underlying Commons FileItem instances.
multipartFiles
- Collection of MultipartFile instancesorg.apache.commons.fileupload.FileItem#delete()
private java.lang.String determineEncoding(java.lang.String contentTypeHeader, java.lang.String defaultEncoding)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |