使用EasyAdmin在VichUploader中无法上传图像

时间:2019-04-17 11:41:20

标签: php symfony vichuploaderbundle easyadmin

我在EasyAdmin配置中使用VichUploader(实际上是EasyAdminPlus,这有点不同)。我已经阅读了与VichUploader相关的所有文档,并查看了YouTube上的一些教程,但找不到错误在哪里。 当我上传图像时,名称在数据库中另存为tmp / ...,但是我所拥有的上传文件中什么都没有显示。 someone猫可以告诉我我的错误在哪里吗?谢谢!

vichuploader.yaml:

parameters:
    app.path.book_pictures: /uploads/images/books

vich_uploader:
    db_driver: orm

    mappings:
        book_pictures:
            uri_prefix: '%app.path.book_pictures%'
            upload_destination: '%kernel.project_dir%/public/uploads/images/books'
            namer: Vich\UploaderBundle\Naming\UniqidNamer

实体书的一部分:(请注意,由于我使用的是“历史记录”,所以我没有updated_at属性。

use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;

/**
 * @ORM\Entity(repositoryClass="App\Repository\BookRepository")
 * @Vich\Uploadable
 */
class Book
{
    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Gedmo\Versioned
     */
    private $picture;

    /**
     * @Vich\UploadableField(mapping="book_pictures", fileNameProperty="picture")
     * @var File
     */
    private $pictureFile;

/**
     * @return mixed
     */
    public function getPictureFile()
    {
        return $this->pictureFile;
    }

    /**
     * @param File|null $pictureFile
     * @throws \Exception
     */
    public function setPictureFile(File $pictureFile = null)
    {
        $this->pictureFile = $pictureFile;
        if ($this->pictureFile instanceof  UploadedFile) {
            $this->updatedAt = new \DateTime('now');
        }
    }

    public function getPicture(): ?string
    {
        return $this->picture;
    }

    public function setPicture(?string $picture): self
    {
        $this->picture = $picture;

        return $this;
    }

我的Book.yaml(EasyAdminPlus)的一部分:(在这里,我使用“类型:文件”,因为出于我不理解的原因,“类型:vich_image”不起作用...)

            new:
                title: title.book.new
                actions: []
                fields:
                    - { property: title, label: field.title }
                    - { property: author, label: field.author, type: easyadmin_autocomplete }
                    - { property: edition, label: field.edition }
                    - { property: publicationYear, label: field.publicationYear }
                    - { property: summary, label: field.summary }
                    - { property: picture, type: file, label: field.picture }

预先,谢谢您的帮助!

0 个答案:

没有答案