|
|||||||||
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 | |
---|---|
protected Log |
logger
|
Constructor Summary | |
---|---|
CommonsFileUploadSupport()
Instantiate a new CommonsFileUploadSupport with its corresponding FileItemFactory and FileUpload instances. |
Method Summary | |
---|---|
protected void |
cleanupFileItems(Collection<MultipartFile> multipartFiles)
Cleanup the Spring MultipartFiles created during multipart parsing, potentially holding temporary data on disk. |
protected 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(List<FileItem> fileItems,
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(String encoding)
Determine an appropriate FileUpload instance for the given encoding. |
void |
setDefaultEncoding(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
Constructor Detail |
---|
public CommonsFileUploadSupport()
newFileItemFactory()
,
newFileUpload(org.apache.commons.fileupload.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 allowedFileUploadBase.setSizeMax(long)
public void setMaxInMemorySize(int maxInMemorySize)
maxInMemorySize
- the maximum in memory size allowedDiskFileItemFactory.setSizeThreshold(int)
public void setDefaultEncoding(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 useServletRequest.getCharacterEncoding()
,
ServletRequest.setCharacterEncoding(java.lang.String)
,
WebUtils.DEFAULT_CHARACTER_ENCODING
,
FileUploadBase.setHeaderEncoding(java.lang.String)
protected String getDefaultEncoding()
public void setUploadTempDir(Resource uploadTempDir) throws IOException
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(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(List<FileItem> fileItems, 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(Collection<MultipartFile> multipartFiles)
Deletes the underlying Commons FileItem instances.
multipartFiles
- Collection of MultipartFile instancesFileItem.delete()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |