symfony - Handle imageupload using symfony2 + VichUploaderBundle + FOSRestBundle, Testing with Postman (chrome extension) -


i trying implement image uploads symfony2 rest server. used vichuploaderbundle handle this. followed instructions posted here.

so added following post.php (entity want attach image to)

/**  * note: not mapped field of entity metadata, simple property.  *   * @vich\uploadablefield(mapping="product_image", filenameproperty="imagename")  *   * @var file $imagefile  */ protected $imagefile;  /**  * @orm\column(type="string", length=255, name="image_name")  *  * @var string $imagename  */ protected $imagename;  /**  * @orm\column(type="datetime")  *  * @var \datetime $updatedat  */ protected $updatedat;      /**  * if manually uploading file (i.e. not using symfony form) ensure instance  * of 'uploadedfile' injected setter trigger  update. if  * bundle's configuration parameter 'inject_on_load' set 'true' setter  * must able accept instance of 'file' bundle inject 1 here  * during doctrine hydration.  *  * @param file|\symfony\component\httpfoundation\file\uploadedfile $image  */ public function setimagefile(file $image = null) {     $this->imagefile = $image;      if ($image) {         // required @ least 1 field changes if using doctrine         // otherwise event listeners won't called , file lost         $this->updatedat = new \datetime('now');     } }  /**  * @return file  */ public function getimagefile() {     return $this->imagefile; }  /**  * @param string $imagename  */ public function setimagename($imagename) {     $this->imagename = $imagename; } 

added following config.yml

vich_uploader:     db_driver: orm     mappings:         product_image:             uri_prefix:         /images/products             upload_destination: %kernel.root_dir%/../web/images/products 

added line posttype.php

->add('imagefile', 'file') 

i'm trying test if functionality working. rest api i'm using postman (chrome extension) try , post new post. here's i'm trying send along error received

enter image description here

ps: have intentionally left out header field content-type application/json gave bad request error.

working form

the problem on server side though. shouldn't have added ->add('imagefile', 'file') posttype.php, instead, added in ther controller $form = $this->createform(new posttype(), $entity, array("method" => $request->getmethod()))->add('imagefile','file');


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -