Issue Bug Closed

#105532FileUpload: Not all options from MimeTypeValidator can be set

Jörg Hofrichter 11/01/24, 22:07 updated 12/02/25, 14:32

Description

The MimeTypeValidator offers the following options:

  • allowedMimeTypes
  • ignoreFileExtensionCheck
  • notAllowedMessage
  • invalidExtensionMessage

However, when using the FileUpload annotation, only the first option is actually passed to the MimeTypeValidator.

Example:

    #[Extbase\FileUpload([
        'validation' => [
            'required' => false,
            'fileSize' => ['minimum' => '0K', 'maximum' => '8M'],
            'allowedMimeTypes' => ['image/png'],
            'ignoreFileExtensionCheck' => True,
            'notAllowedMessage' => 'LLL:EXT:dummy/Resources/Private/Language/locallang.xlf:validation.mimetype.notAllowedMessage',
            'invalidExtensionMessage' => 'LLL:EXT:dummy/Resources/Private/Language/locallang.xlf:validation.mimetype.invalidextension',
         ],
        'uploadFolder' => '1:/user_upload/extbase_multiple_files/',
    ])]
    protected ObjectStorage $files;
 

Reviews 3

History 313

  1. Torben Hansen commented and changed assigned to Torben Hansen <span data-processor="relativetime" data-value="2024-11-02T09:20:15+00:00" > 11/02/24, 09:20 </span>

    This seems to be a conceptional problem with integration of the MimeTypeValidator in the FileUpload attribute. The other validators (e.g. FileSize or ImageDimensions) allow users to pass all validator possible options to the validator instantiation. For the MimeTypeValidator this is not possible, since we use an option of the validator directly instead.

    Better would have been as following:

    #[Extbase\FileUpload([
            'validation' => [
                'required' => false,
                'fileSize' => ['minimum' => '0K', 'maximum' => '8M'],
                'mimeType' => ['allowedMimeTypes' => ['image/png'], 'ignoreFileExtensionCheck' => true],
             ],
            'uploadFolder' => '1:/user_upload/extbase_multiple_files/',
        ])]

    I’ll check with the core team, if we can fix this by adding an additional instantiation of the MimeTypeValidator as shown above.

  2. Torben Hansen commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2024-11-04T14:30:07+00:00" > 11/04/24, 14:30 </span>

    Applied in changeset commit:8b89eaff20a300631f5b9d0470647bd25af2335f.