类 CommonsFileUploadSupport
- java.lang.Object
- org.springframework.web.multipart.commons.CommonsFileUploadSupport
public abstract class CommonsFileUploadSupport extends Object
Base class for multipart resolvers that use Apache 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.
- 从以下版本开始:
- 2.0
- 作者:
- Juergen Hoeller
- 另请参阅:
CommonsMultipartFile,CommonsMultipartResolver,CommonsPortletMultipartResolver
嵌套类概要
嵌套类 修饰符和类型 类 说明 protected static classCommonsFileUploadSupport.MultipartParsingResultHolder for a Map of Spring MultipartFiles and a Map of multipart parameters.
构造器概要
构造器 构造器 说明 CommonsFileUploadSupport()Instantiate a new CommonsFileUploadSupport with its corresponding FileItemFactory and FileUpload instances.
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected voidcleanupFileItems(MultiValueMap<String,MultipartFile> multipartFiles)Cleanup the Spring MultipartFiles created during multipart parsing, potentially holding temporary data on disk.protected CommonsMultipartFilecreateMultipartFile(org.apache.commons.fileupload.FileItem fileItem)Create aCommonsMultipartFilewrapper for the given CommonsFileItem.protected StringgetDefaultEncoding()Determine the default encoding to use for parsing requests.org.apache.commons.fileupload.disk.DiskFileItemFactorygetFileItemFactory()Return the underlyingorg.apache.commons.fileupload.disk.DiskFileItemFactoryinstance.org.apache.commons.fileupload.FileUploadgetFileUpload()Return the underlyingorg.apache.commons.fileupload.FileUploadinstance.protected booleanisUploadTempDirSpecified()Return the temporary directory where uploaded files get stored.protected org.apache.commons.fileupload.disk.DiskFileItemFactorynewFileItemFactory()Factory method for a Commons DiskFileItemFactory instance.protected abstract org.apache.commons.fileupload.FileUploadnewFileUpload(org.apache.commons.fileupload.FileItemFactory fileItemFactory)Factory method for a Commons FileUpload instance.protected CommonsFileUploadSupport.MultipartParsingResultparseFileItems(List<org.apache.commons.fileupload.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 org.apache.commons.fileupload.FileUploadprepareFileUpload(String encoding)Determine an appropriate FileUpload instance for the given encoding.voidsetDefaultEncoding(String defaultEncoding)Set the default character encoding to use for parsing requests, to be applied to headers of individual parts and to form fields.voidsetMaxInMemorySize(int maxInMemorySize)Set the maximum allowed size (in bytes) before uploads are written to disk.voidsetMaxUploadSize(long maxUploadSize)Set the maximum allowed size (in bytes) before an upload gets rejectedvoidsetMaxUploadSizePerFile(long maxUploadSizePerFile)Set the maximum allowed size (in bytes) for each individual file before an upload gets rejected. -1 indicates no limit (the default).voidsetPreserveFilename(boolean preserveFilename)Set whether to preserve the filename as sent by the client, not stripping off path information inCommonsMultipartFile.getOriginalFilename().voidsetUploadTempDir(Resource uploadTempDir)Set the temporary directory where uploaded files get stored.
构造器详细资料
CommonsFileUploadSupport
public CommonsFileUploadSupport()
Instantiate a new CommonsFileUploadSupport with its corresponding FileItemFactory and FileUpload instances.
方法详细资料
getFileItemFactory
public org.apache.commons.fileupload.disk.DiskFileItemFactory getFileItemFactory()
Return the underlyingorg.apache.commons.fileupload.disk.DiskFileItemFactoryinstance. There is hardly any need to access this.- 返回:
- the underlying DiskFileItemFactory instance
getFileUpload
public org.apache.commons.fileupload.FileUpload getFileUpload()
Return the underlyingorg.apache.commons.fileupload.FileUploadinstance. There is hardly any need to access this.- 返回:
- the underlying FileUpload instance
setMaxUploadSize
public void setMaxUploadSize(long maxUploadSize)
Set the maximum allowed size (in bytes) before an upload gets rejected. -1 indicates no limit (the default).- 参数:
maxUploadSize- the maximum upload size allowed- 另请参阅:
FileUploadBase.setSizeMax(long)
setMaxUploadSizePerFile
public void setMaxUploadSizePerFile(long maxUploadSizePerFile)
Set the maximum allowed size (in bytes) for each individual file before an upload gets rejected. -1 indicates no limit (the default).- 参数:
maxUploadSizePerFile- the maximum upload size per file- 从以下版本开始:
- 4.2
- 另请参阅:
FileUploadBase.setFileSizeMax(long)
setMaxInMemorySize
public void setMaxInMemorySize(int maxInMemorySize)
Set the maximum allowed size (in bytes) before uploads are written to disk. Uploaded files will still be received past this amount, but they will not be stored in memory. Default is 10240, according to Commons FileUpload.- 参数:
maxInMemorySize- the maximum in memory size allowed- 另请参阅:
DiskFileItemFactory.setSizeThreshold(int)
setDefaultEncoding
public 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. Default is ISO-8859-1, according to the Servlet spec.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.setCharacterEncodingmethod.- 参数:
defaultEncoding- the character encoding to use- 另请参阅:
ServletRequest.getCharacterEncoding(),ServletRequest.setCharacterEncoding(java.lang.String),WebUtils.DEFAULT_CHARACTER_ENCODING,FileUploadBase.setHeaderEncoding(java.lang.String)
getDefaultEncoding
protected String getDefaultEncoding()
Determine the default encoding to use for parsing requests.
setUploadTempDir
public void setUploadTempDir(Resource uploadTempDir) throws IOException
Set the temporary directory where uploaded files get stored. Default is the servlet container's temporary directory for the web application.
isUploadTempDirSpecified
protected boolean isUploadTempDirSpecified()
Return the temporary directory where uploaded files get stored.
setPreserveFilename
public void setPreserveFilename(boolean preserveFilename)
Set whether to preserve the filename as sent by the client, not stripping off path information inCommonsMultipartFile.getOriginalFilename().Default is "false", stripping off path information that may prefix the actual filename e.g. from Opera. Switch this to "true" for preserving the client-specified filename as-is, including potential path separators.
newFileItemFactory
protected org.apache.commons.fileupload.disk.DiskFileItemFactory newFileItemFactory()
Factory method for a Commons DiskFileItemFactory instance.Default implementation returns a standard DiskFileItemFactory. Can be overridden to use a custom subclass, e.g. for testing purposes.
- 返回:
- the new DiskFileItemFactory instance
newFileUpload
protected abstract org.apache.commons.fileupload.FileUpload newFileUpload(org.apache.commons.fileupload.FileItemFactory fileItemFactory)
Factory method for a Commons FileUpload instance.To be implemented by subclasses.
- 参数:
fileItemFactory- the Commons FileItemFactory to build upon- 返回:
- the Commons FileUpload instance
prepareFileUpload
protected org.apache.commons.fileupload.FileUpload prepareFileUpload(String encoding)
Determine an appropriate FileUpload instance for the given 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- 返回:
- an appropriate FileUpload instance.
parseFileItems
protected CommonsFileUploadSupport.MultipartParsingResult parseFileItems(List<org.apache.commons.fileupload.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.- 参数:
fileItems- the Commons FileIterms to parseencoding- the encoding to use for form fields- 返回:
- the Spring MultipartParsingResult
- 另请参阅:
CommonsMultipartFile(org.apache.commons.fileupload.FileItem)
createMultipartFile
protected CommonsMultipartFile createMultipartFile(org.apache.commons.fileupload.FileItem fileItem)
Create aCommonsMultipartFilewrapper for the given CommonsFileItem.- 参数:
fileItem- the Commons FileItem to wrap- 返回:
- the corresponding CommonsMultipartFile (potentially a custom subclass)
- 从以下版本开始:
- 4.3.5
- 另请参阅:
setPreserveFilename(boolean),CommonsMultipartFile.setPreserveFilename(boolean)
cleanupFileItems
protected void cleanupFileItems(MultiValueMap<String,MultipartFile> multipartFiles)
Cleanup the Spring MultipartFiles created during multipart parsing, potentially holding temporary data on disk.Deletes the underlying Commons FileItem instances.
- 参数:
multipartFiles- Collection of MultipartFile instances- 另请参阅:
FileItem.delete()