0

我在 Symfony 5 上遇到了问题。这两天我使用 AWS S3 来存储我的图像和文档。我也使用 VichImage 上传。如果我使用 VichImage + Gaufrette + AWS S3,它就可以工作(使用公共存储桶,而不是私有存储桶)。

但是如果我想使用 Liip 想象的过滤器,它就行不通了。

请如何配置 Liip 想象以将其与 AWS S3 连接?

服务.yaml:

    app.manager.amazon_s3:
        class: Aws\S3\S3Client
        factory: [Aws\S3\S3Client, 'factory']
        arguments:
            -
                version: '2006-03-01'
                region: 'eu-west-3'
                credentials:
                    key: '%env(AWS_KEY)%'
                    secret: '%env(AWS_SECRET_KEY)%'

    app.imagine.cache.resolver.amazon_s3:
        class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver
        arguments:
            - "@app.manager.amazon_s3"
            - '%env(AWS_BUCKET_NAME)%'
            - "public-read"
            - { Scheme: https }
            - { CacheControl: "max-age=86400" }
        tags:
            - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }

想象一下:

liip_imagine:
    # valid drivers options include "gd" or "gmagick" or "imagick"
    driver: "gd"
    cache: amazon_s3

    resolvers:
        amazon_s3:
            aws_s3:
                client_config:
                    credentials:
                        key: '%env(AWS_KEY)%'
                        secret: '%env(AWS_SECRET_KEY)%'
                    region: 'eu-west-3'
                    bucket: '%env(AWS_BUCKET_NAME)%'
                    version: '2006-03-01'
                bucket: '%env(AWS_BUCKET_NAME)%'
                # cache: true
                get_options:
                    Scheme: https
                put_options:
                    CacheControl: "max-age=86400"

维克:

vich_uploader:
    db_driver: orm
    twig: true
    storage: gaufrette

    mappings:
        photos:
            uri_prefix: '%env(AWS_BASE_URL)%/uploads/utilisateurs'
            upload_destination: photos_fs
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
            inject_on_load: true
            delete_on_update: true
            delete_on_remove: true

        documents:
            uri_prefix:  '%env(AWS_BASE_URL)%/uploads/documents'
            upload_destination: documents_fs
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
            inject_on_load: true
            delete_on_update: true
            delete_on_remove: true

长裙:

knp_gaufrette:
    stream_wrapper: ~
    adapters:
        photos_adapter:
            aws_s3:
               service_id: 'app.manager.amazon_s3'
               bucket_name: '%env(AWS_BUCKET_NAME)%'
               detect_content_type: true
               options:
                   create: true
                   directory: uploads/utilisateurs

        documents_adapter:
            aws_s3:
                service_id: 'app.manager.amazon_s3'
                bucket_name: '%env(AWS_BUCKET_NAME)%'
                detect_content_type: true
                options:
                    create: true
                    directory: uploads/documents

    filesystems:
        photos_fs:
            adapter: photos_adapter

        documents_fs:
            adapter: documents_adapter

和我的树枝代码:

          <img src="{{ vich_uploader_asset(bien, 'photo')  | imagine_filter('photo_bien') }}" class="photo-bien">

谢谢 !

4

0 回答 0