Class ServletFileUpload

java.lang.Object
org.apache.tomcat.util.http.fileupload.FileUploadBase
org.apache.tomcat.util.http.fileupload.FileUpload
org.springframework.web.multipart.commons.ServletFileUpload

public class ServletFileUpload extends org.apache.tomcat.util.http.fileupload.FileUpload

High level API for processing file uploads.

This class handles multiple files per single HTML widget, sent using multipart/mixed encoding type, as specified by RFC 1867. Use parseRequest(HttpServletRequest) to acquire a list of

invalid reference
org.apache.commons.fileupload.FileItem
s associated with a given HTML widget.

How the data for individual parts is stored is determined by the factory used to create them; a given part may be in memory, on disk, or somewhere else.

  • Field Summary

    Fields inherited from class org.apache.tomcat.util.http.fileupload.FileUploadBase

    ATTACHMENT, CONTENT_DISPOSITION, CONTENT_LENGTH, CONTENT_TYPE, FORM_DATA, MULTIPART, MULTIPART_FORM_DATA, MULTIPART_MIXED
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an uninitialized instance of this class.
    ServletFileUpload(org.apache.tomcat.util.http.fileupload.FileItemFactory fileItemFactory)
    Constructs an instance of this class which uses the supplied factory to create FileItem instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.tomcat.util.http.fileupload.FileItemIterator
    getItemIterator(jakarta.servlet.http.HttpServletRequest request)
    Processes an RFC 1867 compliant multipart/form-data stream.
    static final boolean
    isMultipartContent(jakarta.servlet.http.HttpServletRequest request)
    Utility method that determines whether the request contains multipart content.
    Map<String,List<org.apache.tomcat.util.http.fileupload.FileItem>>
    parseParameterMap(jakarta.servlet.http.HttpServletRequest request)
    Processes an RFC 1867 compliant multipart/form-data stream.
    Map<String,List<org.apache.tomcat.util.http.fileupload.FileItem>>
    parseParameterMap(org.apache.tomcat.util.http.fileupload.RequestContext ctx)
    Processes an RFC 1867 compliant multipart/form-data stream.
    List<org.apache.tomcat.util.http.fileupload.FileItem>
    parseRequest(jakarta.servlet.http.HttpServletRequest request)
    Processes an RFC 1867 compliant multipart/form-data stream.

    Methods inherited from class org.apache.tomcat.util.http.fileupload.FileUpload

    getFileItemFactory, setFileItemFactory

    Methods inherited from class org.apache.tomcat.util.http.fileupload.FileUploadBase

    getBoundary, getFieldName, getFileCountMax, getFileName, getFileSizeMax, getHeaderEncoding, getItemIterator, getParsedHeaders, getProgressListener, getSizeMax, newFileItemHeaders, parseRequest, setFileCountMax, setFileSizeMax, setHeaderEncoding, setProgressListener, setSizeMax

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ServletFileUpload

      public ServletFileUpload()
      Constructs an uninitialized instance of this class. A factory must be configured, using setFileItemFactory(), before attempting to parse requests.
      See Also:
      • invalid reference
        FileUpload#FileUpload(FileItemFactory)
    • ServletFileUpload

      public ServletFileUpload(org.apache.tomcat.util.http.fileupload.FileItemFactory fileItemFactory)
      Constructs an instance of this class which uses the supplied factory to create FileItem instances.
      Parameters:
      fileItemFactory - The factory to use for creating file items.
      See Also:
      • FileUpload()
  • Method Details

    • isMultipartContent

      public static final boolean isMultipartContent(jakarta.servlet.http.HttpServletRequest request)
      Utility method that determines whether the request contains multipart content.
      Parameters:
      request - The servlet request to be evaluated. Must be non-null.
      Returns:
      true if the request is multipart; false otherwise.
    • parseRequest

      public List<org.apache.tomcat.util.http.fileupload.FileItem> parseRequest(jakarta.servlet.http.HttpServletRequest request) throws org.apache.tomcat.util.http.fileupload.FileUploadException
      Processes an RFC 1867 compliant multipart/form-data stream.
      Parameters:
      request - The servlet request to be parsed.
      Returns:
      A list of FileItem instances parsed from the request, in the order that they were transmitted.
      Throws:
      org.apache.tomcat.util.http.fileupload.FileUploadException - if there are problems reading/parsing the request or storing files.
    • parseParameterMap

      public Map<String,List<org.apache.tomcat.util.http.fileupload.FileItem>> parseParameterMap(jakarta.servlet.http.HttpServletRequest request) throws org.apache.tomcat.util.http.fileupload.FileUploadException
      Processes an RFC 1867 compliant multipart/form-data stream.
      Parameters:
      request - The servlet request to be parsed.
      Returns:
      A map of FileItem instances parsed from the request.
      Throws:
      org.apache.tomcat.util.http.fileupload.FileUploadException - if there are problems reading/parsing the request or storing files.
      Since:
      1.3
    • getItemIterator

      public org.apache.tomcat.util.http.fileupload.FileItemIterator getItemIterator(jakarta.servlet.http.HttpServletRequest request) throws org.apache.tomcat.util.http.fileupload.FileUploadException, IOException
      Processes an RFC 1867 compliant multipart/form-data stream.
      Parameters:
      request - The servlet request to be parsed.
      Returns:
      An iterator to instances of FileItemStream parsed from the request, in the order that they were transmitted.
      Throws:
      org.apache.tomcat.util.http.fileupload.FileUploadException - if there are problems reading/parsing the request or storing files.
      IOException - An I/O error occurred. This may be a network error while communicating with the client or a problem while storing the uploaded content.
    • parseParameterMap

      public Map<String,List<org.apache.tomcat.util.http.fileupload.FileItem>> parseParameterMap(org.apache.tomcat.util.http.fileupload.RequestContext ctx) throws org.apache.tomcat.util.http.fileupload.FileUploadException
      Processes an RFC 1867 compliant multipart/form-data stream.
      Parameters:
      ctx - The context for the request to be parsed.
      Returns:
      A map of FileItem instances parsed from the request.
      Throws:
      org.apache.tomcat.util.http.fileupload.FileUploadException - if there are problems reading/parsing the request or storing files.
      Since:
      1.3