Could not determine access type for property "file"
<p>I have a little problem with my image upload, can u help me please:</p>

<blockquote>
  <p>Could not determine access type for property "file".</p>
</blockquote>

<p><strong>Controller</strong></p>

<pre><code>/**
 * Creates a new Produits entity.
 *
 */
public function createAction(Request $request)
{
    $entity = new Produits();
    $form = $this-&gt;createCreateForm($entity);
    $form-&gt;handleRequest($request);

    if ($form-&gt;isValid()) {
        $em = $this-&gt;getDoctrine()-&gt;getManager();
        $em-&gt;persist($entity);
        $em-&gt;flush();

        return $this-&gt;redirect($this-&gt;generateUrl('adminProduits_show', array('id' =&gt; $entity-&gt;getId())));
    }

    return $this-&gt;render('EcommerceBundle:Administration:Produits/layout/new.html.twig', array(
        'entity' =&gt; $entity,
        'form'   =&gt; $form-&gt;createView(),
    ));
}

/**
 * Creates a form to create a Produits entity.
 *
 * @param Produits $entity The entity
 *
 * @return \Symfony\Component\Form\Form The form
 */
private function createCreateForm(Produits $entity)
{
    $form = $this-&gt;createForm(ProduitsType::class, $entity);

    $form-&gt;add('submit', SubmitType::class, array('label' =&gt; 'Ajouter'));

    return $form;
}

/**
 * Displays a form to create a new Produits entity.
 *
 */
public function newAction()
{
    $entity = new Produits();
    $form   = $this-&gt;createCreateForm($entity);

    return $this-&gt;render('EcommerceBundle:Administration:Produits/layout/new.html.twig', array(
        'entity' =&gt; $entity,
        'form'   =&gt; $form-&gt;createView(),
    ));
}
</code></pre>

<p><strong>Form</strong></p>

<pre><code>/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
    -&gt;add('file', FileType::class, array('data_class' =&gt; null))
    -&gt;add('name', TextType::class)
    ;
}

/**
 * @param OptionsResolver $resolver
 */
public function configureOptions(OptionsResolver $resolver)
{
    $resolver-&gt;setDefaults(array(
        'data_class' =&gt; 'Ecommerce\EcommerceBundle\Entity\Media'
    ));
}
/**
 * @return string
 */
public function getName()
{
    return 'ecommerce_ecommercebundle_media';
}
</code></pre>

<p><strong>Entity</strong></p>

<pre><code>    /**
 * @ORM\Column(name="name",type="string",length=255)
 * @Assert\NotBlank()
 */
private $name;

/**
 * @ORM\Column(type="string",length=255, nullable=true)
 */
private $path;

/**
 * @Assert\File(
 *     maxSize = "1024k",
 *     mimeTypes = {"image/png", "image/jpg", "image/bmp"},
 *     mimeTypesMessage = "Please upload a valid PDF"
 * )
 */
public $file;

public function getUploadRootDir()
{
    return __dir__.'/../../../../web/uploads';
}

public function getAbsolutePath()
{
    return null === $this-&gt;path ? null : $this-&gt;getUploadRootDir().'/'.$this-&gt;path;
}

public function getAssetPath()
{
    return 'uploads/'.$this-&gt;path;
}

/**
 * @ORM\PrePersist()
 * @ORM\PreUpdate()
 */
public function preUpload()
{
    $this-&gt;tempFile = $this-&gt;getAbsolutePath();
    $this-&gt;oldFile = $this-&gt;getPath();
    $this-&gt;updateAt = new \DateTime();

    if (null !== $this-&gt;file)
        $this-&gt;path = sha1(uniqid(mt_rand(),true)).'.'.$this-&gt;file-&gt;guessExtension();
}

/**
 * @ORM\PostPersist()
 * @ORM\PostUpdate()
 */
public function upload()
{
    if (null !== $this-&gt;file) {
        $this-&gt;file-&gt;move($this-&gt;getUploadRootDir(),$this-&gt;path);
        unset($this-&gt;file);

        if ($this-&gt;oldFile != null) unlink($this-&gt;tempFile);
    }
}

/**
 * @ORM\PreRemove()
 */
public function preRemoveUpload()
{
    $this-&gt;tempFile = $this-&gt;getAbsolutePath();
}

/**
 * @ORM\PostRemove()
 */
public function removeUpload()
{
    if (file_exists($this-&gt;tempFile)) unlink($this-&gt;tempFile);
}

/**
 * Get id
 *
 * @return integer
 */
public function getId()
{
    return $this-&gt;id;
}

public function getPath()
{
    return $this-&gt;path;
}

public function getName()
{
    return $this-&gt;name;
}

public function getFile()
{
    return $this-&gt;file;
}

/**
 * Set path
 *
 * @param string $path
 * @return String
 */
public function setPath($path)
{
    $this-&gt;path = $path;
    return $this;
}

/**
 * Set alt
 *
 * @param string $alt
 * @return String
 */
public function setAlt($alt)
{
    $this-&gt;alt = $alt;
    return $this;
}

/**
 * Set name
 *
 * @param string $name
 * @return String
 */
public function setName($name)
{
    $this-&gt;name = $name;
    return $this;
}

/**
 * Set updateAt
 *
 * @param \DateTime $updateAt
 *
 * @return Media
 */
public function setUpdateAt($updateAt)
{
    $this-&gt;updateAt = $updateAt;

    return $this;
}

/**
 * Get updateAt
 *
 * @return \DateTime
 */
public function getUpdateAt()
{
    return $this-&gt;updateAt;
}
</code></pre>

<p>Thanks for your help guys :)</p>