Skip to content

#[MapUploadedFile] Missing or Invalid 'name' Parameter Causes Type Error #54871

@rcsofttech85

Description

@rcsofttech85

Symfony version(s) affected

7.1

Description

In the changeUserPicture() function, if the 'name' parameter in the MapUploadedFile attribute is missing or invalid, it results in a type error being thrown. This behavior could lead to unexpected exceptions and is not clearly handled.

How to reproduce

    public function changeUserPicture(
        #[MapUploadedFile(
            constraints: new Assert\File(mimeTypes: ['image/png', 'image/jpeg']),

        )] ?UploadedFile $picture
    ): Response
    {
        //
    }

Possible Solution

public function changeUserPicture(
     #[MapUploadedFile(
         constraints:
         new Assert\File(mimeTypes: ['image/png', 'image/jpeg']),
         name:
         'file'
     )] ?UploadedFile $picture
 ): Response
 {
    //
 }

Additional Context

Screenshot from 2024-05-09 18-38-44

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