Skip to content

Ajax file upload broken in v2.7.38 #25725

@stevro

Description

@stevro
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 2.7.38

In v2.7.38 it was introduced a security fix to uploaded files.
PR: #24993

The problem is that if you upload the files using ajax and you use the javascript below for ajax upload:

$('body').on('submit', '.ajaxForm', function (e) {
  var formData = new FormData($(this)[0]);
  $.ajax({
            type: 'POST',
            url: your_url,
            processData: false,
            contentType: false,
            data: formData
        });
}

In Symfony\Component\Form\Extension\Core\Type\FileType::buildForm() when calling $event->getData() you obtain the following structure:

array:1 [▼
  0 => array:1 [▼
    0 => UploadedFile {#13 ▼
      -test: false
      -originalName: "IMG_20171110_150940.jpg"
      -mimeType: "image/jpeg"
      -size: 593894
      -error: 0
    }
  ]
]

And when calling $requestHandler->isFileUpload($file), $file is an array instead of the actual file, and the result will be false.

Is it something that I'm doing wrong when uploading files with ajax and I shouldn't get the structure above, or could we add some extra checks either in FileType?

This is the form config:

$builder               
                ->add('documents', 'file', array(
                    'required' => false,
                    'attr' => array('multiple' => 'multiple'),
                    'mapped' => false,
                    'multiple'=>true,
                ))
        ;

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