title: Symfony2 base64 in Entity to File in Form (and inverse) using DataTransformer
body: <p>I got a blog plateform, with an entity <code>Category</code> this entity has associated to it </p>
  
  <ul>
  <li>a name</li>
  <li>an icon (small 40*40 png)</li>
  </ul>
  
  <p>as the file is very small and mime-type assured to be always png, I've decided to store the file content as a Base64 encoded string in the entity/database </p>
  
  <p>this way the page can be rendered at once without needing to do extra request for very small files (same for the API call <code>GET /api/categories</code> ). for pre-loaded data it works pretty well. The problem come when I want to edit one category</p>
  
  <p>I've created a form with a file type for the icon </p>
  
  <pre><code>public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $transformer = new FileToBase64Transformer();
  
      $iconField = $builder-&gt;create('iconColor', 'file', ['required' =&gt; false]);
      $iconField-&gt;addModelTransformer($transformer);
  
      $builder
          -&gt;add('title')
          -&gt;add($iconField)
      ;
  }
  </code></pre>
  
  <p>the data transformer being </p>
  
  <pre><code>class FileToBase64Transformer implements DataTransformerInterface
  {
      public function transform($base64)
      {
          return null;
      }
      public function reverseTransform($file)
      {
          if (is_null($file)) {
              return null;
          }
  
          return base64_encode(file_get_contents($file));
      }
  }
  </code></pre>
  
  <p>but when i submit the form with a valid image, the form fails
  in the profiler, in form section i can see </p>
  
  <p><code>
   Symfony\Component\Validator\ConstraintViolation
  Object(Symfony\Component\Form\Form).data.icon = THE_BASE_64_OF_THE_FILE
  </code></p>
  
  <p>is it because the data is transformed before the validation happpens ? </p>
  
  <ul>
  <li>how to modify this code to make it pass the validation</li>
  <li>something i need to wrap my head around is what is going to happen when i will edit if the user upload no new image, how can the image be preserved ? </li>
  </ul>