Skip to content

Problem during reading with flysystem #1424

Open
@Servialux

Description

@Servialux
Q A
Bundle version 2.3.0
Symfony version v7.0.2
League/flysystem-bundle 3.3.2
PHP version 8.3.1

I've looked everywhere but unfortunately I can't find my answer. I tried to debug it myself but without success.

I can write correctly in the db and in my ObjectStorage

I've done the classical way (not my first time) to get FlySystem and VichUploader working. I've come to notice that when I request reading entity, VichUploader is not called at all. As a result, I get the following error:

{"message": "Cannot assign string to property App\Entity\Shops::$imageFile of type ?Symfony\Component\HttpFoundation\\File"}

Thank you in advance for an indication or look I attach my files below.

Best regards,
Nestate

Support Question

//Entity/shops
<?php

namespace App\Entity;

use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Doctrine\ORM\Mapping as ORM;

use App\Repository\ShopsRepository;
use Symfony\Component\HttpFoundation\File\File;

#[ORM\Entity(repositoryClass: ShopsRepository::class)]
#[Vich\Uploadable]
class Shops implements EntityFilesInterface
{
// Some var
    #[ORM\Column(length: 255, nullable: true)]
    #[Groups(['get:shop', 'is:file'])]
    #[Vich\UploadableField(mapping: 'shopImage', fileNameProperty: 'imageName', size: 'imageSize')]
    private ?File $imageFile = null;
//Other var and function 
   // Image Functions
    
    /**
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
     * of 'UploadedFile' is injected into this setter to trigger the update. If this
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
     * must be able to accept an instance of 'File' as the bundle will inject one here
     * during Doctrine hydration.
     *
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
     */
    public function setImageFile(?File $imageFile = null): void
    {
        if ($imageFile instanceof File) {
            // It is required that at least one field changes if you are using doctrine
            // otherwise the event listeners won't be called and the file is lost
            $this->updatedAt = new \DateTimeImmutable();
        }
        $this->imageFile = $imageFile;
    }

    public function getImageFile(): ?File
    {
        return $this->imageFile;
    }

    public function setImageName(?string $imageName): void
    {
        $this->imageName = $imageName;
    }

    public function getImageName(): ?string
    {
        return $this->imageName;
    }

    public function setImageSize(?int $imageSize): void
    {
        $this->imageSize = $imageSize;
    }

    public function getImageSize(): ?int
    {
        return $this->imageSize;
    }

My vich_uploader configuration file:


vich_uploader:
    db_driver: orm
    storage: flysystem

    metadata:
        type: attribute

    mappings:
        shopImage:
            uri_prefix: /img/shops/image
            upload_destination: shops.storage
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer

            inject_on_load: true
            delete_on_update: true
            delete_on_remove: true
        logoImage:
            uri_prefix: /img/shops/logo
            upload_destination: shops.storage
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer

            inject_on_load: true
            delete_on_update: true
            delete_on_remove: true


And in a controller as i do:

 $this->em->getRepository(Shops::class)->findAll()

I got the error I've written on top of my message like the bundle is not used for getting from DB I've used them in two projects before this one and I don't understand why this time it doesn't work

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions