0

My Drupal version is 8.6.10

I am trying to upload a file through the file_save_upload function and the function is looking for the file in

Symfony\Component\HttpFoundation\FileBag Object

$all_files = \Drupal::request()->files; debug($all_files); Symfony\Component\HttpFoundation\FileBag Object ( [parameters:protected] => Array ( ) ) 

But my file is in

Symfony\Component\HttpFoundation\ParameterBag Object.

$all_files = \Drupal::request()->request; debug($all_files); Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( [name] => [type] => 4 [files] => Array ( [image_section] => logo_capnord.png ) [op] => Ajouter [form_build_id] => form-wMTrCGaN5mPlOOv8bqS7UsJ0lRiSN6QQp9UviA0cTIA [form_token] => 1hTMXJRfoQvFV9Lqq3TuJ29eYC6L-zt3U7Bow1P8yJ0 [form_id] => capnord_section_form_list ) ) 

The field is generated through the reloading of the form in ajax.

 $form["base"]["fields"] += [ "image_section" => [ "#type" => "file", "#title" => "Image", ] ]; 
2
  • I solved my problem, as I only reloaded one part of the form, the form generator did not know that there was a file element, so it did not add "multipart enctype / form-data" to the form. Commented Mar 14, 2019 at 14:30
  • 1
    If you found a solution please enter it in as an answer Commented Mar 14, 2019 at 18:12

1 Answer 1

0

Solution

$form["#attributes"] = ["enctype" => "multipart/form-data"]; $form["base"]["fields"] += [ "image_section" => [ "#type" => "file", "#title" => "Image", ] ]; 

I solved my problem, as I only reloaded one part of the form, the form generator did not know that there was a file element, so it did not add "multipart enctype / form-data" to the form.

I hope this will help someone in the same situation as me in the future.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.