{"action":"created","issue":{"url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/544","repository_url":"https://api.github.com/repos/dustin10/VichUploaderBundle","labels_url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/544/labels{/name}","comments_url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/544/comments","events_url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/544/events","html_url":"https://github.com/dustin10/VichUploaderBundle/issues/544","id":140427738,"number":544,"title":"Image not uploaded","user":{"login":"Ben00000","id":17804683,"avatar_url":"https://avatars.githubusercontent.com/u/17804683?v=3","gravatar_id":"","url":"https://api.github.com/users/Ben00000","html_url":"https://github.com/Ben00000","followers_url":"https://api.github.com/users/Ben00000/followers","following_url":"https://api.github.com/users/Ben00000/following{/other_user}","gists_url":"https://api.github.com/users/Ben00000/gists{/gist_id}","starred_url":"https://api.github.com/users/Ben00000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ben00000/subscriptions","organizations_url":"https://api.github.com/users/Ben00000/orgs","repos_url":"https://api.github.com/users/Ben00000/repos","events_url":"https://api.github.com/users/Ben00000/events{/privacy}","received_events_url":"https://api.github.com/users/Ben00000/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-12T23:34:20Z","updated_at":"2016-03-17T07:29:02Z","closed_at":null,"body":"Hello,\r\n\r\nI'm trying to upload an image but it doesn't work. Actually my entity is well saved in my database but image is not uploaded.\r\n\r\nHere are my files : \r\n\r\nImage.php : \r\n\r\n<?php\r\n\r\nnamespace CMPUserBundle\\Entity;\r\n\r\nuse Doctrine\\ORM\\Mapping as ORM;\r\nuse Symfony\\Component\\HttpFoundation\\File\\File;\r\nuse Vich\\UploaderBundle\\Mapping\\Annotation as Vich;\r\n\r\n/**\r\n * Image\r\n *\r\n * @ORM\\Table(name=\"image\")\r\n * @ORM\\Entity(repositoryClass=\"CMPUserBundle\\Repository\\ImageRepository\")\r\n * @Vich\\Uploadable\r\n */\r\nclass Image\r\n{\r\n    /**\r\n     * @var int\r\n     *\r\n     * @ORM\\Column(name=\"id\", type=\"integer\")\r\n     * @ORM\\Id\r\n     * @ORM\\GeneratedValue(strategy=\"AUTO\")\r\n     */\r\n    private $id;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"titre\", type=\"string\", length=255)\r\n     */\r\n    private $titre;\r\n\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"description\", type=\"text\")\r\n     */\r\n    private $description;\r\n\r\n\t/**\r\n\t* @ORM\\ManyToOne(targetEntity=\"CMPUserBundle\\Entity\\User\")\r\n\t*/\r\n\tprivate $user;\r\n\r\n\t/**\r\n     * NOTE: This is not a mapped field of entity metadata, just a simple property.\r\n     * \r\n     * @Vich\\UploadableField(mapping=\"product_image\", fileNameProperty=\"imageName\")\r\n     * \r\n     * @var File\r\n     */\r\n    private $imageFile;\r\n\r\n    /**\r\n     * @ORM\\Column(type=\"string\", length=255)\r\n     *\r\n     * @var string\r\n     */\r\n    private $imageName;\r\n\r\n    /**\r\n     * @ORM\\Column(type=\"datetime\")\r\n     *\r\n     * @var \\DateTime\r\n     */\r\n    private $updatedAt;\r\n\r\n\r\n    /**\r\n     * Get id\r\n     *\r\n     * @return integer \r\n     */\r\n    public function getId()\r\n    {\r\n        return $this->id;\r\n    }\r\n\r\n    /**\r\n     * Set titre\r\n     *\r\n     * @param string $titre\r\n     * @return Image\r\n     */\r\n    public function setTitre($titre)\r\n    {\r\n        $this->titre = $titre;\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * Get titre\r\n     *\r\n     * @return string \r\n     */\r\n    public function getTitre()\r\n    {\r\n        return $this->titre;\r\n    }\r\n\r\n    /**\r\n     * Set description\r\n     *\r\n     * @param string $description\r\n     * @return Image\r\n     */\r\n    public function setDescription($description)\r\n    {\r\n        $this->description = $description;\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * Get description\r\n     *\r\n     * @return string \r\n     */\r\n    public function getDescription()\r\n    {\r\n        return $this->description;\r\n    }\r\n\r\n    /**\r\n     * Set user\r\n     *\r\n     * @param \\CMPUserBundle\\Entity\\User $user\r\n     * @return Image\r\n     */\r\n    public function setUser(\\CMPUserBundle\\Entity\\User $user = null)\r\n    {\r\n        $this->user = $user;\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * Get user\r\n     *\r\n     * @return \\CMPUserBundle\\Entity\\User \r\n     */\r\n    public function getUser()\r\n    {\r\n        return $this->user;\r\n    }\r\n\r\n\t/**\r\n     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance\r\n     * of 'UploadedFile' is injected into this setter to trigger the  update. If this\r\n     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter\r\n     * must be able to accept an instance of 'File' as the bundle will inject one here\r\n     * during Doctrine hydration.\r\n     *\r\n     * @param File|\\Symfony\\Component\\HttpFoundation\\File\\UploadedFile $image\r\n     *\r\n     * @return Product\r\n     */\r\n    public function setImageFile(File $image = null)\r\n    {\r\n        $this->imageFile = $image;\r\n\r\n        if ($image) {\r\n            // It is required that at least one field changes if you are using doctrine\r\n            // otherwise the event listeners won't be called and the file is lost\r\n            $this->updatedAt = new \\DateTime('now');\r\n        }\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * @return File\r\n     */\r\n    public function getImageFile()\r\n    {\r\n        return $this->imageFile;\r\n    }\r\n\r\n    /**\r\n     * @param string $imageName\r\n     *\r\n     * @return Product\r\n     */\r\n    public function setImageName($imageName)\r\n    {\r\n        $this->imageName = $imageName;\r\n\r\n        return $this;\r\n    }\r\n\r\n    /**\r\n     * @return string\r\n     */\r\n    public function getImageName()\r\n    {\r\n        return $this->imageName;\r\n    }\r\n}\r\n\r\n\r\nUploadController.php : \r\n\r\n<?php\r\n\r\nnamespace CMPUserBundle\\Controller;\r\n\r\nuse Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;\r\nuse Symfony\\Component\\HttpFoundation\\Response;\r\nuse CMPUserBundle\\Entity\\Image;\r\nuse Symfony\\Component\\HttpFoundation\\Request;\r\n\r\nclass UploadController extends Controller\r\n{\r\n    public function indexAction(Request $request)\r\n    {\r\n\r\n\t// On crée un objet Advert\r\n    $image = new Image();\r\n\r\n    // On crée le FormBuilder grâce au service form factory\r\n    $form = $this->get('form.factory')->createBuilder('form', $image)\r\n\r\n    // On ajoute les champs de l'entité que l'on veut à notre formulaire\r\n\t->add('titre',      'text')\r\n\t->add('description',      'text')\r\n\t->add('imageName',      'text')\r\n    ->add('imageFile',     'file')\r\n\t->add('save',      'submit')\r\n\t->getForm()\r\n    ;\r\n\r\n    $form->handleRequest($request);\r\n\r\n    // On vérifie que les valeurs entrées sont correctes\r\n    // (Nous verrons la validation des objets en détail dans le prochain chapitre)\r\n    if ($form->isValid()) {\r\n      // On l'enregistre notre objet $advert dans la base de données, par exemple\r\n      $em = $this->getDoctrine()->getManager();\r\n\r\n      $em->persist($image);\r\n\r\n      $em->flush();\r\n\r\n      $request->getSession()->getFlashBag()->add('notice', 'Annonce bien enregistrée.');\r\n\r\n      // On redirige vers la page de visualisation de l'annonce nouvellement créée\r\n      //return $this->redirect($this->generateUrl('oc_platform_view', array('id' => $advert->getId())));\r\n\treturn $this->render('CMPUserBundle:Image:add.html.twig', array(\r\n      'form' => $form->createView(),\r\n    ));\r\n    }\r\n\r\n\treturn $this->render('CMPUserBundle:Image:add.html.twig', array(\r\n      'form' => $form->createView(),\r\n    ));\r\n    }\r\n}\r\n\r\n\r\nThank you :)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/comments/197739053","html_url":"https://github.com/dustin10/VichUploaderBundle/issues/544#issuecomment-197739053","issue_url":"https://api.github.com/repos/dustin10/VichUploaderBundle/issues/544","id":197739053,"user":{"login":"Richard-NL","id":116042,"avatar_url":"https://avatars.githubusercontent.com/u/116042?v=3","gravatar_id":"","url":"https://api.github.com/users/Richard-NL","html_url":"https://github.com/Richard-NL","followers_url":"https://api.github.com/users/Richard-NL/followers","following_url":"https://api.github.com/users/Richard-NL/following{/other_user}","gists_url":"https://api.github.com/users/Richard-NL/gists{/gist_id}","starred_url":"https://api.github.com/users/Richard-NL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Richard-NL/subscriptions","organizations_url":"https://api.github.com/users/Richard-NL/orgs","repos_url":"https://api.github.com/users/Richard-NL/repos","events_url":"https://api.github.com/users/Richard-NL/events{/privacy}","received_events_url":"https://api.github.com/users/Richard-NL/received_events","type":"User","site_admin":false},"created_at":"2016-03-17T07:29:02Z","updated_at":"2016-03-17T07:29:02Z","body":"I think I might have the same issue. My config.yml\r\n```yaml\r\nvich_uploader:\r\n    db_driver: orm\r\n\r\n    mappings:\r\n        logo_image:\r\n            namer:              vich_uploader.namer_uniqid\r\n            uri_prefix:         /images/logos\r\n            upload_destination: %kernel.root_dir%/../web/images/logos\r\n            inject_on_load:     false\r\n            delete_on_update:   false\r\n            delete_on_remove:   true\r\n```\r\nMy Entity: (stripped)\r\n```php\r\n\r\n/**\r\n * Company\r\n *\r\n * @Vich\\Uploadable\r\n * @ORM\\Table(name=\"company\")\r\n * @ORM\\Entity(repositoryClass=\"Application\\Repository\\Company\")\r\n * @ORM\\EntityListeners({\"Application\\Listener\\CompanyListener\"})\r\n */\r\nclass Company\r\n    /**\r\n     * @var string\r\n     *\r\n     * @ORM\\Column(name=\"logoImageUrl\", type=\"string\", length=255, nullable=true)\r\n     */\r\n    protected $logoImageUrl;\r\n\r\n    /**\r\n     * @var File $logoImageFile\r\n     * @Vich\\UploadableField(mapping=\"logo_image\", fileNameProperty=\"logoImageUrl\")\r\n     */\r\n    private $logoImageFile;\r\n}\r\n```\r\n\r\nThe weird thing is when is manually set the url string (logoImageUrl) to a value It does get uploaded.\r\n@Ben00000 do you have the same behaviour? when you set the value manually to a string will the file be uploaded"}}