Interface UploadContent

All Superinterfaces:
Serializable

public interface UploadContent extends Serializable
A handle to a fully received upload, passed to UploadValidator.validateComplete(UploadEvent, UploadContent) so that whole-content checks (for example antivirus scanning) can inspect the data before it is delivered to the success callback.

The content is only valid for the duration of the validateComplete call and must not be retained: for a file-backed upload the underlying file may be deleted immediately after the call (for example when the upload is rejected), and any stream handed out is closed by the framework once the call returns.

Since:
25.3
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the path of the file backing this content, if the upload was stored to a file.
    Opens a new stream over the received content.
    long
    Returns the size of the received content in bytes.
  • Method Details

    • getInputStream

      InputStream getInputStream() throws IOException
      Opens a new stream over the received content.

      Each call returns an independent stream positioned at the start. The framework closes any stream returned here once the enclosing validateComplete call returns, so a validator must read within that call and must not retain the stream. When asPath() is present, prefer it for libraries that scan by file path.

      Returns:
      a fresh input stream over the content
      Throws:
      IOException - if the stream cannot be opened
    • size

      long size()
      Returns the size of the received content in bytes.
      Returns:
      the content size in bytes
    • asPath

      Optional<Path> asPath()
      Returns the path of the file backing this content, if the upload was stored to a file.

      Present for file-based upload handlers (FileUploadHandler/TemporaryFileUploadHandler) and empty for in-memory uploads. The path refers to the file produced by the handler's FileFactory; it may be deleted right after validateComplete returns if the upload is rejected.

      Do not hand this path to an asynchronous or background process: read or scan it synchronously within the validateComplete call, since the file may be gone once the call returns.

      Returns:
      the backing file path, or empty if the content is not file-backed