dustin10 / VichUploaderBundle

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

Allow creating directory subfolders by giving the path in the config #1427

Closed syffer closed 2 months ago

syffer commented 7 months ago

name: ⚙ Improvement about: Allowing to set the image subfolders directly from the yaml configuration (without having to rely on property accessor)

Improvement

Q A
New Feature yes
RFC no
BC Break no

Summary

This pr is a proposal to add a new directory namer, which allow to configure the image subfolders directly from the yaml configuration.

This would allow to use multiple vich mapping on the same storage, without

For example, it would allow to do the following:

vich_uploader:
    # ...

    storage: flysystem

    mappings:
        logo:
            uri_prefix: '%app.uploads.uri_prefix%'
            upload_destination: storage.uploads.cdn
            directory_namer:
                service: vich.namer_directory_configurable
                options:
                    directory_path: custom/logos
            namer:
                service: Vich\UploaderBundle\Naming\SmartUniqueNamer

        map:
            uri_prefix: '%app.uploads.uri_prefix%'
            upload_destination: storage.uploads.cdn
            directory_namer:
                service: vich.namer_directory_configurable
                options:
                    directory_path: custom/maps
            namer:
                service: Vich\UploaderBundle\Naming\SmartUniqueNamer

flysystem:
    storages:
        storage.uploads.cdn:
            adapter: 'gcloud'
            visibility: !php/const League\Flysystem\GoogleCloudStorage\PortableVisibilityHandler::NO_PREDEFINED_VISIBILITY
            options:
                client: 'app.uploads_cdn.gcloud_client_service'
                bucket: '%uploads.cdn.gcp.storage.bucket_name%'
                prefix: '%uploads.cdn.gcp.storage.path_prefix%'

This would also take care of #1377