Skip to content

[Form] Validate files uploaded via multiple="multiple" #10804

@jeroenvdheuvel

Description

@jeroenvdheuvel

Since Symfony 2.5 it's possible to upload multiple files: #8224. Currently it's not possible to validate via @Assert\All({@Assert\NotBlank}) when no files are selected before submitting.

It looks like the request is generated in a wrong way, for these kind of uploads.

// $_FILES
array(
    'post' => array(
        'name' => array('image' => array(0 => '',),),
        'type' => array('image' => array(0 => '',),),
        'tmp_name' => array('image' => array(0 => '',),),
        'error' => array('image' => array(0 => 4,),),
        'size' => array('image' => array(0 => 0,),),
    ),
)

// Single file before convertFileInformation
array(
    'name' => array('image' => array(0 => '',),),
    'type' => array('image' => array(0 => '',),),
    'tmp_name' => array('image' => array(0 => '',),),
    'error' => array('image' => array(0 => 4,),),
    'size' => array('image' => array(0 => 0,),),
)

// Single file after convertFileInformation
array(
    'image' => array ( 0 => NULL, ),
)

Instead of creating an empty array of files (in this case images), it has created an array with one item that is null. When validating the images via the All validator with an NotBlank assertion, it throws the InvalidPropertyPathException: Could not parse property path "data.image.[0]". Unexpected token "." at position 10.

This makes it hard to validate multiple files at once.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions