I want to upload files with VichUploaderBundle. There is my Entity
........
/**
*
* @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;
/**
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setImageFile(File $image = null)
{
$this->imageFile = $image;
if ($image) {
$this->updatedAt = new \DateTime('now');
}
}
/**
* @return File
*/
public function getImageFile()
{
return $this->imageFile;
}
/**
* @param string $imageName
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
}
/**
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
.........
My form builder looks like
........
$builder
->add('brand')
->add('model')
->add('price')
->add('imageName')
->add('updatedAt')
->add('sub_rel')
.......
My config file looks like
vich_uploader:
db_driver: orm
mappings:
product_image:
uri_prefix: /images/goods
upload_destination: %kernel.root_dir%/../web/images/goods
inject_on_load: false
delete_on_update: true
delete_on_remove: true
Question: What I need to change in order that I could use this bundle to download a few pictures?
Your form should look like:
And the in your frontend, if you want to display products:
It's all well documented in the bundles documentation: https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/index.md
I would suggest using LiipImagineBundle to generate all the needed thumbnails for your frontend/backend.