Multiple file validation: "This value should be of type string"

I’m trying to use Symfony Validator on a file upload form (form extension’s validation) and I’m getting this error message:

messageTemplate: “This value should be of type string.” from SymfonyComponentValidatorConstraintViolation

Upload works well without the validator, and I cant figure out where this message is coming from.

Here’s my FormType, with a basic validation as doc’s exemple:

            ->add('file', FileType::class, [
                'label' => 'Choisir un fichier',
                'mapped' => false,
                'multiple' => true,
                'constraints' => [
                    new File([
                        'maxSize' => '1024k',
                        'mimeTypes' => [
                        'mimeTypesMessage' => 'Please upload a valid PDF document',

If I remove maxSize, mimeTypes and/or mimeTypesMessage arguments, I still have the same problem.

I can’t use annotations on entity (mapped option is set to false).

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 1

Your email address will not be published. Required fields are marked *