1

我目前在我的 symfony 5 项目上的图像显示有问题。遇到的问题是我使用 liip_imagine 获取图像的 URL 错误。存储桶的名称放置在图像的 url 中,并阻止我访问它。

我得到什么:

https://nameProxy/nameBucket/myDossier/myImage.jpeg

代替

https://nameProxy/myDossier/myImage.jpeg

我在 CDN 中为我的图像和 CloudFront 使用 Amazon S3 服务。

Mon fichier de configuration liip_imagine.yaml :

loaders:
    loader_aws_s3:
        stream:
            wrapper: "gaufrette://fs_images/"

resolvers:

    cache_resolver_aws_s3:
        aws_s3:
            client_config:
                credentials:
                    key:    '%env(AWS_KEY)%'
                    secret: '%env(AWS_SECRET_KEY)%'
                region: 'eu-west-3'
                version: 'latest'
            bucket: 'myBucket'
            get_options:
                Scheme: 'https'
            put_options:
                CacheControl: 'max-age=86400'
            proxies: ['https://myProxy']

filter_sets :
    cache : ~

    layout_user_picture:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [128, 128], mode: outbound, allow_upscale: true }

    admin_layout_user_picture:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [128, 128], mode: inset, allow_upscale: true }

    company_picture:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [256, 128], mode: outbound, allow_upscale: true }

    admin_company_picture:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [256, 128], mode: inset, allow_upscale: true }

    company_picture_big:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [256, 128], mode: inset, allow_upscale: true }

    podcast_user_picture:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [128, 128], mode: outbound, allow_upscale: true }

    image_preview:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [256, 256], mode: outbound, allow_upscale: true }

    podcast_card_cover:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 90
        filters:
            thumbnail: { size: [256, 256], mode: outbound, allow_upscale: true }

    podcast_card_cover_sm:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 90
        filters:
            thumbnail: { size: [56, 56], mode: outbound, allow_upscale: true }

    podcast_card_cover_sm2:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 90
        filters:
            thumbnail: { size: [92, 92], mode: outbound, allow_upscale: true }

    podcast_cover_list_entry:
        data_loader: loader_aws_s3
        cache: cache_resolver_aws_s3
        quality: 100
        filters:
            thumbnail: { size: [250, 156], mode: outbound, allow_upscale: true }

服务.yaml:

aws.s3.client:
    class: Aws\S3\S3Client
    factory: [Aws\S3\S3Client, 'factory']
    arguments:
        -   version: latest
            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:
        - "@aws.s3.client"
        - "nameBucket"
    calls:
        - [ setGetOption, [ Scheme, https ] ]
        - [ setPutOption, [ CacheControl, "max-age=86400" ] ]
    tags:
        - { name: "liip_imagine.cache.resolver", resolver: "amazon_s3" }

knp_gaufrette.yaml:

knp_gaufrette:
    stream_wrapper: ~

    adapters:
        images:
            aws_s3:
                service_id: 'aws.s3.client'
                bucket_name: 'nameBucket'
                detect_content_type: true
                options:
                    directory: 'images'

        medias:
            aws_s3:
                service_id: 'aws.s3.client'
                bucket_name: 'nameBucket'
                detect_content_type: true
                options:
                    directory: 'medias'

    filesystems:
        fs_images:
            adapter: images

        fs_medias:
            adapter: medias

vich_uploarder.yaml:

vich_uploader:
    db_driver: orm
    storage: gaufrette
    mappings:
        images:
            uri_prefix:         ''
            upload_destination: fs_images
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
            inject_on_load: false
            delete_on_remove: true

        medias:
            uri_prefix:         ''
            upload_destination: fs_medias
            namer: Vich\UploaderBundle\Naming\SmartUniqueNamer
            inject_on_load: false
            delete_on_remove: true

欢迎帮助,提前感谢您的合作;)

4

0 回答 0