config.yml
vich_uploader:
db_driver: orm
mappings:
media_image:
uri_prefix: '%uploads_dir%'
upload_destination: '%kernel.root_dir%/../web/uploads/images'
namer: Vich\UploaderBundle\Naming\OrignameNamer
Entity:
/**
* Media
* @Vich\Uploadable
* @ORM\Table(name="medias")
* @ORM\Entity(repositoryClass="AppBundle\Repository\MediaRepository")
*/
class Media
{
use TimestampableEntity;
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
private $imageName;
/**
* @Vich\UploadableField(mapping="media_image", fileNameProperty="imageName", mimeType="mimeType", size="size")
* @var File
*/
private $imageFile;
/**
* @var string
*
* @ORM\Column(name="mime_type", type="string", length=20, nullable=true)
*/
private $mimeType;
/**
* @var string
*
* @ORM\Column(name="size", type="integer", nullable=true)
*/
private $size;
When I enable namer
, I am getting this error:
Any ideas why?
The (custom-)namer should be registered as a service and referred to by its service name.
You can see the default (long) configuration together with a list of namer services provided by VichUploaderBundle in the example below:
vich_uploader:
# [..]
mappings:
product_image_file:
# [..]
namer:
# one of: vich_uploader.namer_{uniqid,origname,property,hash}
service: vich_uploader.namer_origname
For reference, here are all namer services as listed by the command bin/console debug:container
:
vich_uploader.namer_base64 Vich\UploaderBundle\Naming\Base64Namer
vich_uploader.namer_directory_property Vich\UploaderBundle\Naming\PropertyDirectoryNamer
vich_uploader.namer_hash Vich\UploaderBundle\Naming\HashNamer
vich_uploader.namer_origname Vich\UploaderBundle\Naming\OrignameNamer
vich_uploader.namer_property Vich\UploaderBundle\Naming\PropertyNamer
vich_uploader.namer_uniqid Vich\UploaderBundle\Naming\niqidNamer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With