title: how to add profile picture in UserEntity with FosUserBundle
body: <p>I try to add a profile picture in my user Entity but i fail , i work with symfony 3 and fosuserbundle , for doing this work , I use a listner , here my entire code :
  the code of my <code>UserEntity</code>:</p>
  
  <pre><code>namespace Forum\ForumBundle\Entity;
  
  use FOS\UserBundle\Model\User as BaseUser;
  use Doctrine\ORM\Mapping as ORM;
  use Symfony\Component\Validator\Constraints as Assert;
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\Security\Core\Util\SecureRandom;
  use Doctrine\Common\Collections\ArrayCollection;
  use Symfony\Component\HttpFoundation\File\File;
  
  /**
   * @ORM\Entity
   * @ORM\Table(name="fos_user")
   * @ORM\HasLifecycleCallbacks()
   */
  class User extends BaseUser
  
  {
  
      /**
       * @ORM\Column(type="string")
       *
       * @Assert\NotBlank(message="Please, upload the product brochure as a PDF file.")
       * @Assert\Image(
       *     
       * )
       */
      private $brochure;
  
      public function getBrochure()
      {
          return $this-&gt;brochure;
      }
  
      public function setBrochure(File $file = null)
      {
         $this-&gt;brochure = $file;
  
          return $this;
      }
  
  public function __construct()
      {
          parent::__construct();
           $this-&gt;test = false; 
           //  $this-&gt;uploadProfilePicture();
          // your own logic
      }
  
  }
  </code></pre>
  
  <p>My listener :</p>
  
  <pre><code>namespace Forum\ForumBundle\EventListener;
  
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Doctrine\ORM\Event\LifecycleEventArgs;
  use Doctrine\ORM\Event\PreUpdateEventArgs;
  use Forum\ForumBundle\Entity\User;
  use Forum\ForumBundle\FileUploader;
  
  class BrochureUploadListener
  {
      private $uploader;
  
      public function __construct(FileUploader $uploader)
      { 
          $this-&gt;uploader = $uploader;
      }
  
      public function prePersist(LifecycleEventArgs $args)
      {die("good");
          $entity = $args-&gt;getEntity();
  
          $this-&gt;uploadFile($entity);
      }
  
      public function preUpdate(PreUpdateEventArgs $args)
      {
          $entity = $args-&gt;getEntity();
  
          $this-&gt;uploadFile($entity);
      }
  
      private function uploadFile($entity)
      {
          // upload only works for Product entities
          if (!$entity instanceof Product) {
              return;
          }
  
          $file = $entity-&gt;getBrochure();
  
          // only upload new files
          if (!$file instanceof UploadedFile) {
              return;
          }
  
          $fileName = $this-&gt;uploader-&gt;upload($file);
          $entity-&gt;setBrochure($fileName);
      }
  }
  </code></pre>
  
  <p>the listener use Uploader file :</p>
  
  <pre><code>namespace Forum\ForumBundle;
  
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  
  class FileUploader
  {
      private $targetDir;
  
      public function __construct($targetDir)
      {
          $this-&gt;targetDir = $targetDir;
      }
  
      public function upload(UploadedFile $file)
      {
          $fileName = md5(uniqid()).'.'.$file-&gt;guessExtension();
  
          $file-&gt;move($this-&gt;targetDir, $fileName);
  
          return $fileName;
      }
  }
  </code></pre>
  
  <p>I configure my services as well</p>
  
  <pre><code> app.brochure_uploader:
          class: Forum\ForumBundle\FileUploader
          arguments: ['%brochures_directory%']
      app.doctrine_brochure_listener:
          class: Forum\ForumBundle\EventListener\BrochureUploadListener
          arguments: ['@app.brochure_uploader']
          tags:
              - { name: doctrine.event_listener, event: prePersist }
              - { name: doctrine.event_listener, event: preUpdate }
  </code></pre>
  
  <p>an I declare the parameter :brochure-directory in config.yml</p>
  
  <pre><code>parameters:
      locale: fr
      brochures_directory: 'web/uploads/brochures'
  </code></pre>
  
  <p>the probleme is when I update my entity , the bro</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
  
  /*
   * This file is part of the FOSUserBundle package.
   *
   * (c) FriendsOfSymfony &lt;http://friendsofsymfony.github.com/&gt;
   *
   * For the full copyright and license information, please view the LICENSE
   * file that was distributed with this source code.
   */
  
  namespace FOS\UserBundle\Controller;
  
  use FOS\UserBundle\FOSUserEvents;
  use FOS\UserBundle\Event\FormEvent;
  use FOS\UserBundle\Event\FilterUserResponseEvent;
  use FOS\UserBundle\Event\GetResponseUserEvent;
  use FOS\UserBundle\Model\UserInterface;
  use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\RedirectResponse;
  use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  
  /**
   * Controller managing the user profile
   *
   * @author Christophe Coevoet &lt;stof@notk.org&gt;
   */
  class ProfileController extends Controller
  {
      /**
       * Show the user
       */
      public function showAction()
      {
          $user = $this-&gt;getUser();
          if (!is_object($user) || !$user instanceof UserInterface) {
              throw new AccessDeniedException('This user does not have access to this section.');
          }
  
          return $this-&gt;render('FOSUserBundle:Profile:show.html.twig', array(
              'user' =&gt; $user
          ));
      }
  
      /**
       * Edit the user
       */
      public function editAction(Request $request)
      {
          $user = $this-&gt;getUser();
          if (!is_object($user) || !$user instanceof UserInterface) {
              throw new AccessDeniedException('This user does not have access to this section.');
          }
  
          /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
          $dispatcher = $this-&gt;get('event_dispatcher');
  
          $event = new GetResponseUserEvent($user, $request);
          $dispatcher-&gt;dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
  
          if (null !== $event-&gt;getResponse()) {
              return $event-&gt;getResponse();
          }
  
          /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
          $formFactory = $this-&gt;get('fos_user.profile.form.factory');
  
          $form = $formFactory-&gt;createForm();
          $form-&gt;setData($user);
  
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isValid()) {
              /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
              $userManager = $this-&gt;get('fos_user.user_manager');
  
              $event = new FormEvent($form, $request);
              $dispatcher-&gt;dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
  
              $userManager-&gt;updateUser($user);
  
              if (null === $response = $event-&gt;getResponse()) {
                  $url = $this-&gt;generateUrl('fos_user_profile_show');
                  $response = new RedirectResponse($url);
              }
  
              $dispatcher-&gt;dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
  
              return $response;
          }
  
          return $this-&gt;render('FOSUserBundle:Profile:edit.html.twig', array(
              'form' =&gt; $form-&gt;createView()
          ));
      }
  }</code></pre>
  </div>
  </div>
  </p>