The upload of my images with the Vich Uploader Bundle is working fine, they are stored in the correct directory and in the database. However when trying to access them or display them, they are not find. (Object not found exception or just displaying an empty square.
Any ideas why this might be?
the config:
vich_uploader:
db_driver: orm
mappings:
carousel:
uri_prefix: %kernel.root_dir%/web/uploads/carousel
upload_destination: '%kernel.root_dir%/web/uploads/carousel'
namer: vich_uploader.namer_origname
Also, my setter of the imageFile is not working at all. When uploading an Image for the first time, everything is set (updatedAt, imageSize, imageName) except for the imageFile, which is always null..
e.g.
Image {#1601 ▼
-id: 1
-imageFile: null
-imageSize: 34703
-imageName: "5a7f9db650f78_EntityType.png"
-updatedAt: DateTime {#1599 ▼
}
}
here is my Entity:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* Image
*
* @ORM\Table(name="app_image")
* @ORM\Entity
* @Vich\Uploadable
*/
class Image {
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="carousel", fileNameProperty="imageName", size="imageSize")
* @Assert\File()
* @var File
*/
private $imageFile;
/**
* @ORM\Column(type="integer")
*
* @var integer
*/
private $imageSize;
/**
* @var string
* @ORM\Column(type="string", nullable=false)
*/
private $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
private $updatedAt;
public function getImageFile(){
return $this->imageFile;
}
/**
*
* @param \Symfony\Component\HttpFoundation\File\File|\Symfony\Component\HttpFoundation\File\UploadedFile $file
*
* @return File
*/
public function setImageFile(\Symfony\Component\HttpFoundation\File\File $image = null)
{
$this->imageFile = $image;
if ($image instanceof File) {
$this->updatedAt = new \DateTime();
}
return $this;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set updatedAt
*
* @param \DateTime $updatedAt
*
* @return Image
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* Get updatedAt
*
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* Set imageSize
*
* @param integer $imageSize
*
* @return Image
*/
public function setImageSize($imageSize)
{
$this->imageSize = $imageSize;
return $this;
}
/**
* Get imageSize
*
* @return integer
*/
public function getImageSize()
{
return $this->imageSize;
}
/**
* Set imageName
*
* @param string $imageName
*
* @return Image
*/
public function setImageName($imageName)
{
$this->imageName = $imageName;
return $this;
}
/**
* Get imageName
*
* @return string
*/
public function getImageName()
{
return $this->imageName;
}
}
I have the feeling that this is caused by a 'deeper' problem in my installation or anything, because everything is working fine until that point. If I e.g. the part with
if ($image instanceof File) {
$this->updatedAt = new \DateTime();
}
of the setter is commented out, I get an updatedAt can't be null exception, so somehow the setter is accessed but it's not setting the image as an Uploaded File.
Am I using the wrong directory or wrong access rights, or what else could it be?