Class FileValidationService

java.lang.Object
formflow.library.file.FileValidationService

@Service public class FileValidationService extends Object
This service is intended to help with miscellaneous file things. This service will help with checking mime types, both proper mime-type names like "image/jpeg" and with file extensions. The current list of accepted file mime-types are:
  • .bmp : image/bmp
  • .doc : application/msword"
  • .docx : application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • .gif : image/gif
  • .jpeg : image/jpeg
  • .jpg : image/jpeg
  • .pdf : application/pdf
  • .png : image/png
  • .odp : application/vnd.oasis.opendocument.presentation
  • .ods : application/vnd.oasis.opendocument.spreadsheet
  • .odt : application/vnd.oasis.opendocument.text
  • Field Details

  • Constructor Details

    • FileValidationService

      public FileValidationService(@Value("${form-flow.uploads.accepted-file-types:\'\'}") String userProvidedFileTypes, @Value("${form-flow.uploads.max-file-size}") Integer maxFileSize)
  • Method Details

    • getAcceptableFileExts

      public List<String> getAcceptableFileExts()
      Returns the list of file extensions the system accepts: ".bmp, .doc"
      Returns:
      List of strings containing the acceptable file extensions for the system
    • isAcceptedMimeType

      public Boolean isAcceptedMimeType(org.springframework.web.multipart.MultipartFile file)
      Returns True if the file is of the appropriate mime type for the system setup. This takes into account the configuration set in the application's configuration.
      Parameters:
      file - the file to check the mime type of
      Returns:
      Boolean True if the mimetype is one of the ones the system accepts, False otherwise.
    • acceptedFileTypes

      public String acceptedFileTypes()
      Provides the list of acceptable file types the system accepts in a string form, like so: ".bmp,.jpg"
      Returns:
      String a string containing a list of acceptable file extensions: ".bmp,.jpg"
    • isTooLarge

      public boolean isTooLarge(org.springframework.web.multipart.MultipartFile file)
    • getMaxFileSizeInMb

      public Long getMaxFileSizeInMb()