Skip to content
Advertisement

symfony handle request upload file is null

I’m trying to upload multiple files on Symfony but when the form is submitted the form image field returns a null object like this

JavaScript

But when I get files directly inside the request files attributes file exist. I’ve tried to upload a file by accessing the attribute in the request, it works but it still wants to upload file via Symfony $form request handler.

That’s my controller

JavaScript

The couleur entity

JavaScript

This is the image entity

JavaScript

and this is the couleur type

JavaScript

and finally the image type

JavaScript

Advertisement

Answer

I think you shouldn’t add the mapped => false option in the ImageNewFileType.

https://symfony.com/doc/current/reference/forms/types/form.html#mapped

As you can see in the documentation the field is ignored when writing to the object.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement