title: Synfony 2 File Uploader with Doctrine 2
body: <p>I want to make a simple file uploader with Symfony 2 and Doctrine 2.
  I've follow this tutorial : 
  <a href="http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html" rel="nofollow">http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html</a>
  and this one :
  <a href="http://leny-bernard.com/fr/afficher/article/creer-un-site-facilement-en-symfony2-partie-4" rel="nofollow">http://leny-bernard.com/fr/afficher/article/creer-un-site-facilement-en-symfony2-partie-4</a></p>
  
  <p>Here is my Entity class :</p>
  
  <p>
  
  <pre><code>namespace Luna\KBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\HttpFoundation\File\File;
  
  /**
  * Luna\KBundle\Entity\Media
  *
  * @ORM\Entity
  */
  class Media
  {
  /**
   * @var integer $id
   */
  private $id;
  
  /**
   * @var string $title
   */
  private $title;
  
  /**
   * @var text $description
   */
  private $description;
  
  /**
   * @var string $author
   */
  private $author;
  
  /**
   * @var string $source
   */
  private $source;
  
  /**
   * @Assert\File(maxSize="6000000")
   */
  private $paths;
  
  /**
   * @var string $type
   */
  private $type;
  
  /**
   * @var Luna\KBundle\Entity\object
   */
  private $idobject;
  /***********************************METHODS***********************************/
  
  /**
   * Set idobject
   *
   * @param Luna\KBundle\Entity\Object $idobject
   */
  public function setIdobject(\Luna\KBundle\Entity\object $idobject)
  {
      $this-&gt;idObject = $idObject;
  }
  
  /**
   * Get idObject
   *
   * @return Luna\KBundle\Entity\Object 
   */
  public function getIdObject()
  {
      return $this-&gt;idObject;
  }
  
  /**
   * Get id
   *
   * @return integer 
   */
  public function getId()
  {
      return $this-&gt;id;
  }
  
  /**
   * Set title
   *
   * @param string $title
   */
  public function setTitle($title)
  {
      $this-&gt;title = $title;
  }
  
  /**
   * Get title
   *
   * @return string 
   */
  public function getTitle()
  {
      return $this-&gt;title;
  }
  
  /**
   * Set description
   *
   * @param text $description
   */
  public function setDescription($description)
  {
      $this-&gt;description = $description;
  }
  
  /**
   * Get description
   *
   * @return text 
   */
  public function getDescription()
  {
      return $this-&gt;description;
  }
  
  /**
   * Set author
   *
   * @param string $author
   */
  public function setAuthor($author)
  {
      $this-&gt;author = $author;
  }
  
  /**
   * Get author
   *
   * @return string 
   */
  public function getAuthor()
  {
      return $this-&gt;author;
  }
  
  /**
   * Set source
   *
   * @param string $source
   */
  public function setSource($source)
  {
      $this-&gt;source = $source;
  }
  
  /**
   * Get source
   *
   * @return string 
   */
  public function getSource()
  {
      return $this-&gt;source;
  }
  
  /**
   * Set paths
   *
   * @param string $paths
   */
  public function setPaths($paths)
  {
      $this-&gt;paths = $paths;
  }
  
  /**
   * Get paths
   *
   * @return string 
   */
  public function getPaths()
  {
      return $this-&gt;paths;
  }
  
  /**
   * Set type
   *
   * @param string $type
   */
  public function setType($type)
  {
      $this-&gt;type = $type;
  }
  
  /**
   * Get type
   *
   * @return string 
   */
  public function getType()
  {
      return $this-&gt;type;
  }
  
  
  public function getAbsolutePath()
  {
      return null === $this-&gt;paths ? null : $this-&gt;getUploadRootDir().'/'.$this-&gt;paths;
  }
  
  public function getWebPath()
  {
      return null === $this-&gt;paths ? null : $this-&gt;getUploadDir().'/'.$this-&gt;paths;
  }
  
  protected function getUploadRootDir()
  {
      // the absolute directory path where uploaded documents should be saved
      return __DIR__.'/../../../../web/'.$this-&gt;getUploadDir();
  }
  
  protected function getUploadDir()
  {
      // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
      return 'uploads/mediaobject';
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The fact is that @Assert\File(maxSize="6000000") is not working : I don't have a file uploader but just a simple texte field ?!</p>
  
  <p>How can I make this works correctly ?</p>
  
  <p>Regards Guys :)</p>
  
  <p>EDIT : Here my Form builder</p>
  
  <p>
  
  <pre><code>namespace Luna\KBundle\Form;
  
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilder;
  
  class MediaInit extends AbstractType
  {
  public function buildForm(FormBuilder $builder, array $options)
  {
      $builder
          -&gt;add('title')
          -&gt;add('description')
          -&gt;add('author')
          -&gt;add('source')
          -&gt;add('paths')
          -&gt;add('type')
          -&gt;add('idObject')            
      ;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And Here my twig template :</p>
  
  <pre><code>{% extends '::layout.html.twig' %}
  {####################################### MEDIA INIT###########################}
  {% block content %}
  
  
  &lt;h1&gt;Creer un Media&lt;/h1&gt;
  
  Entrez les informations de votre media ici
  
  &lt;form action="{{ path('media_init') }}" method="post" {{ form_enctype(form) }}&gt;
  {{ form_widget(form) }}
  &lt;p&gt;
      &lt;button type="submit"&gt;Creer&lt;/button&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  
  
  {% endblock %}
  </code></pre>