dustin10 / VichUploaderBundle

A simple Symfony bundle to ease file uploads with ORM entities and ODM documents.
MIT License
1.85k stars 519 forks source link

Cannot locate filesystem service with oneup/flysystem-bundle #1337

Closed Thomerdos closed 1 year ago

Thomerdos commented 1 year ago

Bug Report

Q A
BC Break no
Bundle version 2.0.1
Symfony version 6.1
PHP version 8.1.5

Summary

I'm trying to use a filesystem with oneup/flysystem-bundle but the filesystem service is not found.

Current behavior

I'm getting the following error when uploading :

Service "oneup_flysystem.s3_filesystem" not found: the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator that is empty...

How to reproduce

This is my configuration :

services:
  # default configuration for services in *this* file
  _defaults:
    autowire: true      # Automatically injects dependencies in your services.
    autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    public: true

  # makes classes in src/ available to be used as services
  # this creates a service per class whose id is the fully-qualified class name
  App\:
    resource: '../src/'
    exclude:
      - '../src/DependencyInjection/'
      - '../src/Entity/'
      - '../src/Kernel.php'

  app.s3_client:
    public: true
    class: Aws\S3\S3Client
    factory: [Aws\S3\S3Client, 'factory' ]
    arguments:
      - version: latest
        region: kubernative
        credentials:
          key: '%env(AWS_KEY)%'
          secret: '%env(AWS_SECRET_KEY)%'

vich_uploader:
    db_driver: orm
    storage: flysystem

    mappings:
        images:
            uri_prefix: "%env(AWS_BASE_URL)%/%env(AWS_BUCKET_NAME)%/images"
            upload_destination: oneup_flysystem.s3_filesystem
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer

oneup_flysystem:
  adapters:
    default_adapter:
      awss3v3:
        client: app.s3_client
        bucket: '%env(AWS_BUCKET_NAME)%'
  filesystems:
    s3:
      adapter: default_adapter

The s3_filesystem service has this configuration :

Information for Service "oneup_flysystem.s3_filesystem"
=======================================================

 ---------------- -------------------------------------- 
  Option           Value                                
 ---------------- --------------------------------------
  Service ID       oneup_flysystem.s3_filesystem
  Class            League\Flysystem\Filesystem
  Tags             oneup_flysystem.filesystem (key: s3)
  Public           yes
  Synthetic        no
  Lazy             no
  Shared           yes
  Abstract         no
  Autowired        no
  Autoconfigured   no
 ---------------- --------------------------------------

I searched a lot but found nothing relevant, I don't understand why the service locator is empty. I tried a debug:container command but didn't see anything special. I also tried to downgrade to version 1.x but I had the same issue.

Edit : I checked the source code and saw the RegisterFlysystemRegistryPass and VichUploaderBundle classes but wasn't able to dump anything...

Expected behavior

Being able to use the filesystem correctly. I'm not quite sure if it is a vichuploaderbundle issue or a misconfiguration.

Thanks for your help,

Thomerdos commented 1 year ago

I found the issue, the mount option was missing under the filesystem...

  filesystems:
    s3:
      mount: s3
      adapter: default_adapter
mhbailly commented 6 months ago

Thanks for posting the solution @Thomerdos

I found the issue, the mount option was missing under the filesystem...

  filesystems:
    s3:
      mount: s3
      adapter: default_adapter

I struggled on my end because it was not clear to me that the mount value (s3) has to be the same asthe identifier of the filesystem (s3). I tried initially to use another value (like s3_mount) to avoid confusion in my code but that was not working.

Really unclear to me what the "mount" parameter does and how it works. Hopefully, this helps someone else