Interface UploadFileValidator

All Known Implementing Classes:
SvgUploadValidator

public interface UploadFileValidator
Validates uploaded files without altering their content.

Implementations must be selective in supports(String, String) so the centralized upload service does not inspect large unrelated files such as Office documents, PDFs, archives, videos, etc.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    supports(String fileName, String mimeType)
     
    void
    validate(String fileName, String mimeType, InputStream inputStream)
    Validates the uploaded file in read-only mode.
  • Method Details

    • supports

      boolean supports(String fileName, String mimeType)
      Parameters:
      fileName - uploaded file name
      mimeType - detected or enriched MIME type
      Returns:
      true only when this validator must inspect the uploaded file
    • validate

      void validate(String fileName, String mimeType, InputStream inputStream) throws org.apache.commons.fileupload2.core.FileUploadException
      Validates the uploaded file in read-only mode.

      The provided InputStream is owned by the caller. Implementations must read from it but must not close it.

      The stream is expected to be positioned at the beginning of the uploaded content. When several validators support the same file, the caller should provide a fresh stream to each validator.

      Parameters:
      fileName - uploaded file name
      mimeType - detected or enriched MIME type
      inputStream - upload file InputStream
      Throws:
      org.apache.commons.fileupload2.core.FileUploadException - when the upload must be rejected