使用Vich Uploader Bundle上传我的图像工作正常,它们存储在正确的目录和数据库中 . 但是,当试图访问它们或显示它们时,它们找不到 . (找不到对象异常或只显示空方块 .

任何想法为什么会这样?

配置:

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

另外,我的imageFile的setter根本不工作 . 首次上传图像时,除了imageFile之外,一切都已设置(updatedAt,imageSize,imageName),而imageFile始终为null .

例如

Image {#1601 ▼ 
    -id: 1 
    -imageFile: null 
    -imageSize: 34703 
    -imageName: "5a7f9db650f78_EntityType.png" 
    -updatedAt: DateTime {#1599 ▼ 
    } 
  }

这是我的实体:

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;
    } 

}

我觉得这是由我的安装中的“更深层次”问题或任何事情引起的,因为在此之前一切正常 . 如果我与...的部分

if ($image instanceof File) {
    $this->updatedAt = new \DateTime();
  }

注释掉了setter,我得到了一个 updatedAt can't be null 异常,因此以某种方式访问了setter但它没有将图像设置为Uploaded File . 我使用了错误的目录或错误的访问权限,还是它还有什么用呢?

先感谢您!