Class AbstractFileUploadBase

  • Direct Known Subclasses:
    FileUpload

    public abstract class AbstractFileUploadBase
    extends Object

    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.

    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.

    Version:
    $Id: FileUploadBase.java 963609 2010-07-13 06:56:47Z jochen $
    Author:
    Rafal Krzewski, Daniel Rall, Jason van Zyl, John McNally, Martin Cooper, Sean C. Sullivan
    • Constructor Detail

      • AbstractFileUploadBase

        public AbstractFileUploadBase()
    • Method Detail

      • getFileItemFactory

        @Nonnull
        public abstract IFileItemFactory getFileItemFactory()
        Returns the factory class used when creating file items.
        Returns:
        The factory class for new file items.
      • getSizeMax

        @CheckForSigned
        public long getSizeMax()
        Returns the maximum allowed size of a complete request, as opposed to getFileSizeMax().
        Returns:
        The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.
        See Also:
        setSizeMax(long)
      • setSizeMax

        public void setSizeMax​(long nSizeMax)
        Sets the maximum allowed size of a complete request, as opposed to setFileSizeMax(long).
        Parameters:
        nSizeMax - The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit.
        See Also:
        getSizeMax()
      • setFileSizeMax

        public void setFileSizeMax​(long nFileSizeMax)
        Sets the maximum allowed size of a single uploaded file, as opposed to getSizeMax().
        Parameters:
        nFileSizeMax - Maximum size of a single uploaded file.
        See Also:
        getFileSizeMax()
      • getHeaderEncoding

        @Nullable
        public String getHeaderEncoding()
        Retrieves the character encoding used when reading the headers of an individual part. When not specified, or null, the request encoding is used. If that is also not specified, or null, the platform default encoding is used.
        Returns:
        The encoding used to read part headers.
      • setHeaderEncoding

        public void setHeaderEncoding​(@Nullable
                                      String sHeaderEncoding)
        Specifies the character encoding to be used when reading the headers of individual part. When not specified, or null, the request encoding is used. If that is also not specified, or null, the platform default encoding is used.
        Parameters:
        sHeaderEncoding - The encoding used to read part headers.
      • getProgressListener

        @Nullable
        public IProgressListener getProgressListener()
        Returns the progress listener.
        Returns:
        The progress listener, if any. Maybe null.
      • setProgressListener

        public void setProgressListener​(@Nullable
                                        IProgressListener aListener)
        Sets the progress listener.
        Parameters:
        aListener - The progress listener, if any. May be to null.
      • getItemIterator

        @Nonnull
        public IFileItemIterator getItemIterator​(@Nonnull
                                                 IRequestContext aCtx)
                                          throws FileUploadException,
                                                 IOException
        Processes an RFC 1867 compliant multipart/form-data stream.
        Parameters:
        aCtx - The context for the request to be parsed.
        Returns:
        An iterator to instances of FileItemStream parsed from the request, in the order that they were transmitted.
        Throws:
        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.
      • parseRequest

        @Nonnull
        @ReturnsMutableCopy
        public com.helger.commons.collection.impl.ICommonsList<IFileItem> parseRequest​(@Nonnull
                                                                                       IRequestContext aCtx)
                                                                                throws FileUploadException
        Processes an RFC 1867 compliant multipart/form-data stream.
        Parameters:
        aCtx - The context for the request to be parsed.
        Returns:
        A list of FileItem instances parsed from the request, in the order that they were transmitted.
        Throws:
        FileUploadException - if there are problems reading/parsing the request or storing files.
      • getBoundary

        @Nullable
        protected byte[] getBoundary​(@Nonnull
                                     String sContentType)
        Retrieves the boundary from the Content-type header.
        Parameters:
        sContentType - The value of the content type header from which to extract the boundary value.
        Returns:
        The boundary, as a byte array.
      • getFileName

        @Nullable
        protected String getFileName​(@Nonnull
                                     IFileItemHeaders aHeaders)
        Retrieves the file name from the Content-disposition header.
        Parameters:
        aHeaders - The HTTP headers object.
        Returns:
        The file name for the current encapsulation.
      • getFieldName

        @Nullable
        protected String getFieldName​(@Nonnull
                                      IFileItemHeaders aFileItemHeaders)
        Retrieves the field name from the Content-disposition header.
        Parameters:
        aFileItemHeaders - A Map containing the HTTP request headers.
        Returns:
        The field name for the current encapsulation.
      • getParsedHeaders

        @Nonnull
        protected IFileItemHeaders getParsedHeaders​(@Nonnull
                                                    String sHeaderPart)

        Parses the header-part and returns as key/value pairs.

        If there are multiple headers of the same names, the name will map to a comma-separated list containing the values.

        Parameters:
        sHeaderPart - The header-part of the current encapsulation.
        Returns:
        A Map containing the parsed HTTP request headers.