title: symfony handle request upload file is null
body: <p>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</p>
  <pre><code>object(Doctrine\Common\Collections\ArrayCollection)#1455 (1) {
    [&quot;elements&quot;:&quot;Doctrine\Common\Collections\ArrayCollection&quot;:private]=&gt;
    array(1) {
      [0]=&gt;
      object(AdminBundle\Entity\ImageNew)#1717 (5) {
        [&quot;nom&quot;:&quot;AdminBundle\Entity\ImageNew&quot;:private]=&gt;
        NULL
        [&quot;path&quot;:&quot;AdminBundle\Entity\ImageNew&quot;:private]=&gt;
        NULL
        [&quot;idimage&quot;:&quot;AdminBundle\Entity\ImageNew&quot;:private]=&gt;
        NULL
        [&quot;categorie&quot;:&quot;AdminBundle\Entity\ImageNew&quot;:private]=&gt;
        NULL
        [&quot;file&quot;:&quot;AdminBundle\Entity\ImageNew&quot;:private]=&gt;
        NULL
      }
    }
  }
  </code></pre>
  <p>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.</p>
  <p>That's my controller</p>
  <pre><code> public function addColorAction(Request $request, Article $article)
      {
          $couleur = new Couleur();
          $form = $this-&gt;createForm('AdminBundle\Form\CouleurType', $couleur);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
  
              $em = $this-&gt;getDoctrine()-&gt;getManager();
  
              $files = $couleur-&gt;getImages();
  
              echo &quot;&lt;pre&gt;&quot;;
              var_dump($files); die;
              
              $imgs = $request-&gt;files-&gt;get(&quot;adminbundle_couleur&quot;)[&quot;images&quot;];
  
              foreach ($imgs as $img) {
                  $image = new ImageNew();
                  $image-&gt;setFile($img[&quot;file&quot;]);
                  $image-&gt;upload();
                  $couleur-&gt;addImage($image);
  
                  $em-&gt;persist($image);
                  $em-&gt;flush();
              }
  
              $color_art_dispo = new CouleurArticleDispo();
              $color_art_dispo-&gt;setEnStock(true);
              $color_art_dispo-&gt;setArticle($article);
              $color_art_dispo-&gt;setCouleur($couleur);
              
              $em-&gt;persist($couleur);
              $em-&gt;persist($color_art_dispo);
              $em-&gt;flush();
  
              return $this-&gt;redirectToRoute('article_index');
          }
  
          return $this-&gt;render(
              'admin/article/couleur/new.html.twig', array(
              'couleur' =&gt; $couleur,
              'form' =&gt; $form-&gt;createView(),)
          );
      }
  </code></pre>
  <p>The couleur entity</p>
  <pre><code>class Couleur
  {
      /**
       * @var int
       *
       * @ORM\Column(name=&quot;id&quot;, type=&quot;integer&quot;)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy=&quot;AUTO&quot;)
       */
      private $id;
  
      /**
       * @var string
       *
       * @ORM\Column(name=&quot;nom&quot;, type=&quot;string&quot;, length=255)
       * @Assert\NotBlank(message=&quot;Veuillez entrer le nom de la couleur&quot;)
       */
      private $nom;
  
      /**
       * @var string
       *
       * @ORM\Column(name=&quot;code_couleur&quot;, type=&quot;string&quot;, length=6)
       * @Assert\NotBlank(message=&quot;Veuillez entrer le code couleur correspondant&quot;)
       * @Assert\Length(
       *     min=6,
       *     max=6,
       *     minMessage=&quot;Le code couleur n'est pas correct.&quot;,
       *     maxMessage=&quot;Le code couleur n'est pas correct.&quot;,
       * )
       */
      private $codeCouleur;
  
      /** 
       * 
       * @ORM\OneToMany(targetEntity=&quot;CouleurArticleDispo&quot;, mappedBy=&quot;_couleurs&quot;)
       */
      private $colorArticles;
  
      /**
       * Many Colors have Many Images.
       * 
       * @ORM\ManyToMany(targetEntity=&quot;ImageNew&quot;,cascade={&quot;remove&quot;})
       * @ORM\JoinTable(name=&quot;color_images&quot;,joinColumns={@ORM\JoinColumn(name=&quot;color_id&quot;,referencedColumnName=&quot;id&quot;, onDelete=&quot;CASCADE&quot;)},
       *      inverseJoinColumns={@ORM\JoinColumn(name=&quot;image_id&quot;, referencedColumnName=&quot;idimage&quot;, onDelete=&quot;CASCADE&quot;)}
       * )
       */
      private $images;
  
      public function __toString()
      {
          return (string) $this-&gt;getNom();
      }
  
      /**
       * Class Constructor
       */
      public function __construct() 
      {
          $this-&gt;images = new ArrayCollection();
      }
  }
  </code></pre>
  <p>This is the image entity</p>
  <pre><code>class ImageNew
  {
      /**
       * @var string
       *
       * @ORM\Column(name=&quot;nom&quot;, type=&quot;string&quot;, length=100)
       */
      private $nom;
  
      /**
       * @var string
       *
       * @ORM\Column(name=&quot;path&quot;, type=&quot;string&quot;, length=255)
       */
      private $path;
  
      /**
       * @var integer
       *
       * @ORM\Column(name=&quot;idimage&quot;,type=&quot;integer&quot;)
       * @ORM\Id
       * @ORM\GeneratedValue(strategy=&quot;IDENTITY&quot;)
       */
      private $idimage;
  
      /**
       * @var \AdminBundle\Entity\Categorie
       *
       * @ORM\ManyToOne(targetEntity=&quot;AdminBundle\Entity\Categorie&quot;,cascade={&quot;persist&quot;},inversedBy=&quot;slides&quot;)
       * @ORM\JoinColumns({
       *   @ORM\JoinColumn(name=&quot;id_categorie&quot;,referencedColumnName=&quot;idcategorie&quot;,nullable=true,onDelete=&quot;SET NULL&quot;)
       * })
       */
      private $categorie;
  
      /**
       * @Assert\NotNull()
       * @Assert\File(
       *     maxSize = &quot;6000k&quot;,
       *     mimeTypes = {&quot;image/png&quot;, &quot;image/jpg&quot;, &quot;image/bmp&quot;},
       *     mimeTypesMessage = &quot;Please upload a valid Image File (PNG, JPEG or BMP)&quot;
       * )
       */
      private $file;
  
      public function __toString()
      {
          return (string) $this-&gt;getPath();
      }
  }
  </code></pre>
  <p>and this is the couleur type</p>
  <pre><code>class CouleurType extends AbstractType
  {
      /**
       * {@inheritdoc}
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder
              -&gt;add('nom')
              -&gt;add('codeCouleur')
              -&gt;add(
                  'images', CollectionType::class, 
                  array(
                      'label' =&gt; 'Images de l\'article ayant cette couleur',
                      'entry_type' =&gt; ImageNewFileType::class,
                      'allow_add' =&gt; true,
                      'allow_delete' =&gt; true,
                  )
              );
      }
  }
  </code></pre>
  <p>and finally the image type</p>
  <pre><code>class ImageNewFileType extends AbstractType
  {
      /**
       * {@inheritdoc}
       */
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add(
              'file', FileType::class, 
              [
                  'mapped' =&gt; false,
                  'required' =&gt; false,
                  'attr' =&gt; array(
                      'accept' =&gt; 'image/*',
                  )
              ]
          );
      }
  }
  </code></pre>