org.appng.forms

## Interface FormUpload

- All Known Implementing Classes:
    FormUploadBean

      public interface FormUpload

  A `FormUpload` represents a `File` which was uploaded through a HTML form using `<input type="file">`.
  Author:
    Matthias Müller

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `List<String>` | `getAcceptedTypes()` Returns a `List` of accepted file-extensions (without `.`)/content-types for this `FormUpload`.
    `byte[]` | `getBytes()` Returns the bytes of the uploaded `File`.
    `String` | `getContentType()` Returns the content-type (if any) for this `FormUpload`.
    `File` | `getFile()` Returns the `File` which has been locally saved, but only if `isValid()` returns `true`.
    `long` | `getMaxSize()` Returns the maximum size (in bytes) for the uploaded `File` (default: -1, which means there is no limit).
    `long` | `getMinSize()` Returns the minimum size (in bytes) for the uploaded file (default: 0).
    `String` | `getOriginalFilename()` Returns the name of the original (without any path prefix) file which was uploaded.
    `boolean` | `isValid()` Returns `true` if, and only if, all of those methods return `true`: `isValidFile()` `isValidSize()` `isValidType()`
    `boolean` | `isValid(Class<? extends FormUploadValidator> validatorClass)` Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
    `boolean` | `isValid(FormUploadValidator validator)` Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
    `boolean` | `isValid(String[] types, long minSize, long maxSize)` Checks whether this `FormUpload` has one of the given types and matches the given size restrictions.
    `boolean` | `isValidFile()` Checks whether the `File` for this `FormUpload` exists and `File.isFile()` returns `true` .
    `boolean` | `isValidSize()` Checks whether the `File` has a valid size.
    `boolean` | `isValidType()` Checks whether the `File`'s extension or content-type are contained in the list of accepted types for this `FormUpload`.
    `long` | `size()` Returns the size (in bytes) of the uploaded `File`.

- - ### Method Detail

    - #### getOriginalFilename

          String getOriginalFilename()

      Returns the name of the original (without any path prefix) file which was uploaded.
      Returns:
        the name of the original file

    - #### getFile

          File getFile()

      Returns the `File` which has been locally saved, but only if `isValid()` returns `true`. The name of this file may have nothing to do with the file's original name.
      Returns:
        the `File`, or `null` if no file was uploaded or `isValid()` returns `false`
      See Also:
        `getOriginalFilename()`

    - #### getBytes

          byte[] getBytes()

      Returns the bytes of the uploaded `File`.
      Returns:
        the bytes

    - #### size

          long size()

      Returns the size (in bytes) of the uploaded `File`.
      Returns:
        the size

    - #### getMinSize

          long getMinSize()

      Returns the minimum size (in bytes) for the uploaded file (default: 0).
      Returns:
        the minimum size

    - #### getMaxSize

          long getMaxSize()

      Returns the maximum size (in bytes) for the uploaded `File` (default: -1, which means there is no limit).
      Returns:
        the maximum size

    - #### isValid

          boolean isValid()

      Returns `true` if, and only if, all of those methods return `true`:
      - `isValidFile()`
      - `isValidSize()`
      - `isValidType()`
      Returns:
        `true` if this `FormUpload` is valid, `false` otherwise.

    - #### isValid

          boolean isValid(FormUploadValidator validator)

      Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
      Parameters:
        `validator` - a `FormUploadValidator`
      Returns:
        the result returned by `FormUploadValidator.isValid(FormUpload)`

    - #### isValid

          boolean isValid(Class<? extends FormUploadValidator> validatorClass)

      Calls `FormUploadValidator.isValid(FormUpload)` using this `FormUpload` and returns the result.
      Parameters:
        `validatorClass` - a type extending `FormUploadValidator`
      Returns:
        the result returned by `FormUploadValidator.isValid(FormUpload)`

    - #### isValid

          boolean isValid(String[] types,
                          long minSize,
                          long maxSize)

      Checks whether this `FormUpload` has one of the given types and matches the given size restrictions. Delegates to `isValidSize()` and `isValidType()`.
      Parameters:
        `types` - an array containing the allowed file-extensions (without `.`) and content-types
        `minSize` - the minimum size of the file (in bytes)
        `maxSize` - the maximum size of the file (in bytes)
      Returns:
        `true` if this `FormUpload` is valid, `false` otherwise.
      See Also:
        `isValidSize()`, `isValidType()`, `getContentType()`, `getAcceptedTypes()`

    - #### isValidSize

          boolean isValidSize()

      Checks whether the `File` has a valid size. Note that by default, there is no minimum size. The default maximum size is provided by the concrete `FormUpload`.
      Returns:
        `true` if the file's size is valid, `false` otherwise
      See Also:
        `isValid(String[], long, long)`, `getMinSize()`, `getMaxSize()`

    - #### isValidType

          boolean isValidType()

      Checks whether the `File`'s extension or content-type are contained in the list of accepted types for this `FormUpload`. If `getAcceptedTypes()` is `null` or empty, all types are allowed.
      Returns:
        `true` if the uploaded `File` has a valid type, `false` otherwise.
      See Also:
        `getAcceptedTypes()`, `getContentType()`

    - #### getAcceptedTypes

          List<String> getAcceptedTypes()

      Returns a `List` of accepted file-extensions (without `.`)/content-types for this `FormUpload`.
      Returns:
        the list of accepted types
      See Also:
        `getContentType()`

    - #### isValidFile

          boolean isValidFile()

      Checks whether the `File` for this `FormUpload` exists and `File.isFile()` returns `true` .
      Returns:
        `true` if the `File` is valid, `false` otherwise

    - #### getContentType

          String getContentType()

      Returns the content-type (if any) for this `FormUpload`. Usually the content-type has been retrieved using `ServletRequest.getContentType()`
      Returns:
        the content type for this `FormUpload`, or `null`

Copyright © 2011–2023 aiticon GmbH. All rights reserved.