title: Symfony 2: Upload file and save as blob
body: <p>I'm trying to save images in database with forms and Doctrine. In my entity, I've done this:</p>
  
  <pre><code>/**
   * @ORM\Column(name="photo", type="blob", nullable=true)
   */
  private $photo;
  
  private $file;
  
  
  /**
   * @ORM\PrePersist()
   * @ORM\PreUpdate()
   */
  public function upload()
  {
      if (null === $this-&gt;file) {
          return;
      }
  
      $this-&gt;setPhoto(file_get_contents($this-&gt;getFile()));
  }
  </code></pre>
  
  <p>And I've also added this in my form type:</p>
  
  <pre><code>-&gt;add('file', 'file')
  </code></pre>
  
  <p>But I'm getting this error when I upload a file:</p>
  
  <blockquote>
    <p>Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile'
    is not allowed</p>
  </blockquote>