Skip to content

Form using Validator Constraint File - Max File Size not validating correctly, element returns NULL #13291

@0mars

Description

@0mars

When submitting a file greater than the max file size, and then trying to get the UploadedFile, it returns null instead of an UploadedFile instance.

use Symfony\Component\Validator\Constraints\File;
// adding form element
$form->add('my_file', 'file', [
                'required' => true,
                'constraints' => [
                    new File([
                        'maxSize' => '5M',
                        'mimeTypes' => [
                            'application/pdf',
                            'application/x-pdf',
                        ],
                        'mimeTypesMessage' => 'Please upload a valid PDF',
                    ])
                ]
            ]);
// in controller
$form->submit($this->getRequest()->request->all());
var_dump($form->get('my_file')->getData());

Actual:

NULL

Expected:

Symfony\Component\HttpFoundation\File\UploadedFile Object

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions