Top Description Inners Fields Constructors Methods
org.springframework.web.multipart.support

public Class StandardMultipartHttpServletRequest

extends AbstractMultipartHttpServletRequest
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, .Serializable, java.nio.file.Files, .Path, java.util.ArrayList, .Collection, .Collections, .Enumeration, .LinkedHashMap, .LinkedHashSet, .Map, .Set, jakarta.servlet.http.HttpServletRequest, .Part, org.springframework.http.ContentDisposition, .HttpHeaders, org.springframework.lang.Nullable, org.springframework.util.FileCopyUtils, .LinkedMultiValueMap, .MultiValueMap, org.springframework.web.multipart.MaxUploadSizeExceededException, .MultipartException, .MultipartFile

Spring MultipartHttpServletRequest adapter, wrapping a Servlet HttpServletRequest and its Part objects. Parameters get exposed through the native request's getParameter methods - without any custom processing on our side.
Authors
Juergen Hoeller, Rossen Stoyanchev
Since
3.1
See Also
StandardServletMultipartResolver

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StandardMultipartHttpServletRequest.StandardMultipartFile

Spring MultipartFile adapter, wrapping a Servlet Part object.

Field Summary

Modifier and TypeField and Description
private Set<String>

Constructor Summary

AccessConstructor and Description
public
StandardMultipartHttpServletRequest(HttpServletRequest
the servlet request to wrap
request
)

Create a new StandardMultipartHttpServletRequest wrapper for the given request, immediately parsing the multipart content.

public
StandardMultipartHttpServletRequest(HttpServletRequest
the servlet request to wrap
request
,
boolean
whether multipart parsing should be triggered lazily on first access of multipart files or parameters
lazyParsing
)

Create a new StandardMultipartHttpServletRequest wrapper for the given request.

Method Summary

Modifier and TypeMethod and Description
public String
getMultipartContentType(String
the name of the part
paramOrFileName
)

Implements org.springframework.web.multipart.MultipartRequest.getMultipartContentType.

Determine the content type of the specified request part.

public HttpHeaders
getMultipartHeaders(String paramOrFileName)

Implements org.springframework.web.multipart.MultipartHttpServletRequest.getMultipartHeaders.

Return the headers for the specified part of the multipart request.

public Map<String, String[]>
getParameterMap()

Overrides jakarta.servlet.ServletRequestWrapper.getParameterMap.

Implements jakarta.servlet.ServletRequest.getParameterMap.

Returns a java.util.Map of the parameters of this request.

public Enumeration<String>
getParameterNames()

Overrides jakarta.servlet.ServletRequestWrapper.getParameterNames.

Implements jakarta.servlet.ServletRequest.getParameterNames.

Returns an Enumeration of String objects containing the names of the parameters contained in this request.

protected void
protected void
private void
Inherited from org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest:
getFilegetFileMapgetFileNamesgetFilesgetMultiFileMapgetMultipartFilesgetRequestgetRequestHeadersgetRequestMethodisResolvedsetMultipartFiles

Field Detail

multipartParameterNamesback to summary
private Set<String> multipartParameterNames
Annotations
@Nullable

Constructor Detail

StandardMultipartHttpServletRequestback to summary
public StandardMultipartHttpServletRequest(HttpServletRequest request) throws MultipartException

Create a new StandardMultipartHttpServletRequest wrapper for the given request, immediately parsing the multipart content.

Parameters
request:HttpServletRequest

the servlet request to wrap

Exceptions
MultipartException:
if parsing failed
StandardMultipartHttpServletRequestback to summary
public StandardMultipartHttpServletRequest(HttpServletRequest request, boolean lazyParsing) throws MultipartException

Create a new StandardMultipartHttpServletRequest wrapper for the given request.

Parameters
request:HttpServletRequest

the servlet request to wrap

lazyParsing:boolean

whether multipart parsing should be triggered lazily on first access of multipart files or parameters

Exceptions
MultipartException:
if an immediate parsing attempt failed
Since
3.2.9

Method Detail

getMultipartContentTypeback to summary
public String getMultipartContentType(String paramOrFileName)

Implements org.springframework.web.multipart.MultipartRequest.getMultipartContentType.

Doc from org.springframework.web.multipart.MultipartRequest.getMultipartContentType.

Determine the content type of the specified request part.

Parameters
paramOrFileName:String

the name of the part

Returns:String

the associated content type, or null if not defined

Annotations
@Override
getMultipartHeadersback to summary
public HttpHeaders getMultipartHeaders(String paramOrFileName)

Implements org.springframework.web.multipart.MultipartHttpServletRequest.getMultipartHeaders.

Doc from org.springframework.web.multipart.MultipartHttpServletRequest.getMultipartHeaders.

Return the headers for the specified part of the multipart request.

If the underlying implementation supports access to part headers, then all headers are returned. Otherwise, e.g. for a file upload, the returned headers may expose a 'Content-Type' if available.

Annotations
@Override
getParameterMapback to summary
public Map<String, String[]> getParameterMap()

Overrides jakarta.servlet.ServletRequestWrapper.getParameterMap.

Implements jakarta.servlet.ServletRequest.getParameterMap.

Doc from jakarta.servlet.ServletRequest.getParameterMap.

Returns a java.util.Map of the parameters of this request. Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.

Returns:Map<String, String[]>

an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.

Annotations
@Override
getParameterNamesback to summary
public Enumeration<String> getParameterNames()

Overrides jakarta.servlet.ServletRequestWrapper.getParameterNames.

Implements jakarta.servlet.ServletRequest.getParameterNames.

Doc from jakarta.servlet.ServletRequest.getParameterNames.

Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.

Returns:Enumeration<String>

an Enumeration of String objects, each String containing the name of a request parameter; or an empty Enumeration if the request has no parameters

Annotations
@Override
handleParseFailureback to summary
protected void handleParseFailure(Throwable ex)
initializeMultipartback to summary
protected void initializeMultipart()

Overrides org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest.initializeMultipart.

Doc from org.springframework.web.multipart.support.AbstractMultipartHttpServletRequest.initializeMultipart.

Lazily initialize the multipart request, if possible. Only called if not already eagerly initialized.

Annotations
@Override
parseRequestback to summary
private void parseRequest(HttpServletRequest request)
org.springframework.web.multipart.support back to summary

private Class StandardMultipartHttpServletRequest.StandardMultipartFile

extends Object
implements MultipartFile, Serializable
Class Inheritance
  • java.lang.Object
  • org.springframework.web.multipart.support.StandardMultipartHttpServletRequest.StandardMultipartFile
All Implemented Interfaces
java.io.Serializable, org.springframework.web.multipart.MultipartFile, org.springframework.core.io.InputStreamSource
Annotations
@SuppressWarnings:serial

Spring MultipartFile adapter, wrapping a Servlet Part object.

Field Summary

Modifier and TypeField and Description
private final String
private final Part

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public byte[]
getBytes()

Implements org.springframework.web.multipart.MultipartFile.getBytes.

Return the contents of the file as an array of bytes.

public String
getContentType()

Implements org.springframework.web.multipart.MultipartFile.getContentType.

Return the content type of the file.

public InputStream
getInputStream()

Implements org.springframework.web.multipart.MultipartFile.getInputStream.

Return an InputStream to read the contents of the file from.

public String
getName()

Implements org.springframework.web.multipart.MultipartFile.getName.

Return the name of the parameter in the multipart form.

public String
getOriginalFilename()

Implements org.springframework.web.multipart.MultipartFile.getOriginalFilename.

Return the original filename in the client's filesystem.

public long
getSize()

Implements org.springframework.web.multipart.MultipartFile.getSize.

Return the size of the file in bytes.

public boolean
isEmpty()

Implements org.springframework.web.multipart.MultipartFile.isEmpty.

Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.

public void
transferTo(File
the destination file (typically absolute)
dest
)

Implements org.springframework.web.multipart.MultipartFile.transferTo.

Transfer the received file to the given destination file.

public void
transferTo(Path dest)

Overrides default org.springframework.web.multipart.MultipartFile.transferTo.

Transfer the received file to the given destination file.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

filenameback to summary
private final String filename
partback to summary
private final Part part

Constructor Detail

StandardMultipartFileback to summary
public StandardMultipartFile(Part part, String filename)

Method Detail

getBytesback to summary
public byte[] getBytes() throws IOException

Implements org.springframework.web.multipart.MultipartFile.getBytes.

Doc from org.springframework.web.multipart.MultipartFile.getBytes.

Return the contents of the file as an array of bytes.

Returns:byte[]

the contents of the file as bytes, or an empty byte array if empty

Annotations
@Override
Exceptions
IOException:
in case of access errors (if the temporary store fails)
getContentTypeback to summary
public String getContentType()

Implements org.springframework.web.multipart.MultipartFile.getContentType.

Doc from org.springframework.web.multipart.MultipartFile.getContentType.

Return the content type of the file.

Returns:String

the content type, or null if not defined (or no file has been chosen in the multipart form)

Annotations
@Override
getInputStreamback to summary
public InputStream getInputStream() throws IOException

Implements org.springframework.web.multipart.MultipartFile.getInputStream.

Doc from org.springframework.web.multipart.MultipartFile.getInputStream.

Return an InputStream to read the contents of the file from.

The user is responsible for closing the returned stream.

Returns:InputStream

the contents of the file as stream, or an empty stream if empty

Annotations
@Override
Exceptions
IOException:
in case of access errors (if the temporary store fails)
getNameback to summary
public String getName()

Implements org.springframework.web.multipart.MultipartFile.getName.

Doc from org.springframework.web.multipart.MultipartFile.getName.

Return the name of the parameter in the multipart form.

Returns:String

the name of the parameter (never null or empty)

Annotations
@Override
getOriginalFilenameback to summary
public String getOriginalFilename()

Implements org.springframework.web.multipart.MultipartFile.getOriginalFilename.

Doc from org.springframework.web.multipart.MultipartFile.getOriginalFilename.

Return the original filename in the client's filesystem.

This may contain path information depending on the browser used, but it typically will not with any other than Opera.

Note

Please keep in mind this filename is supplied by the client and should not be used blindly. In addition to not using the directory portion, the file name could also contain characters such as ".." and others that can be used maliciously. It is recommended to not use this filename directly. Preferably generate a unique one and save this one somewhere for reference, if necessary.

Returns:String

the original filename, or the empty String if no file has been chosen in the multipart form, or null if not defined or not available

Annotations
@Override
getSizeback to summary
public long getSize()

Implements org.springframework.web.multipart.MultipartFile.getSize.

Doc from org.springframework.web.multipart.MultipartFile.getSize.

Return the size of the file in bytes.

Returns:long

the size of the file, or 0 if empty

Annotations
@Override
isEmptyback to summary
public boolean isEmpty()

Implements org.springframework.web.multipart.MultipartFile.isEmpty.

Doc from org.springframework.web.multipart.MultipartFile.isEmpty.

Return whether the uploaded file is empty, that is, either no file has been chosen in the multipart form or the chosen file has no content.

Annotations
@Override
transferToback to summary
public void transferTo(File dest) throws IOException, IllegalStateException

Implements org.springframework.web.multipart.MultipartFile.transferTo.

Doc from org.springframework.web.multipart.MultipartFile.transferTo.

Transfer the received file to the given destination file.

This may either move the file in the filesystem, copy the file in the filesystem, or save memory-held contents to the destination file. If the destination file already exists, it will be deleted first.

If the target file has been moved in the filesystem, this operation cannot be invoked again afterwards. Therefore, call this method just once in order to work with any storage mechanism.

Note

Depending on the underlying provider, temporary storage may be container-dependent, including the base directory for relative destinations specified here (e.g. with Servlet multipart handling). For absolute destinations, the target file may get renamed/moved from its temporary location or newly copied, even if a temporary copy already exists.

Parameters
dest:File

the destination file (typically absolute)

Annotations
@Override
Exceptions
IOException:
in case of reading or writing errors
IllegalStateException:
if the file has already been moved in the filesystem and is not available anymore for another transfer
transferToback to summary
public void transferTo(Path dest) throws IOException, IllegalStateException

Overrides default org.springframework.web.multipart.MultipartFile.transferTo.

Doc from org.springframework.web.multipart.MultipartFile.transferTo.

Transfer the received file to the given destination file.

The default implementation simply copies the file input stream.

Annotations
@Override