symfony – 使用SonataMediaBundle上传到AmazonS3

我想知道如何在Symfony2中包装aws php sdk(aws/aws-sdk-php)以便在SonataMediaBundle中用作cdn.

我现在的奏鸣曲:

sonata_media:
    default_context: default
    db_driver: doctrine_orm
    contexts:
        default:
            providers:
                - sonata.media.provider.image

            formats:
                default: { width: 100 , height: 100, quality: 70}

        avatar:
            providers:
                - sonata.media.provider.image

            formats:
                medium: { width: 750 , quality: 90}

    cdn:
        server:
            path: http://%s3_bucket_name%.s3-website-%s3_region%.amazonaws.com/%env%

    providers:
        image:
            filesystem: sonata.media.filesystem.s3
            service:    sonata.media.provider.image

    filesystem:
        local:
            directory:  %kernel.root_dir%/../web/uploads/media
            create:     false
        s3:
            bucket: %s3_bucket_name%
            accessKey: %s3_access_key%
            secretKey: %s3_secret_key%
            region: %s3_region%@
            directory: %env%

但是我收到一个错误:尝试从全局命名空间加载类“AmazonS3”.

最佳答案
显然,使用配置文件是正确的做法,在这种情况下,我们以这种方式解决了我们的问题:

cdn:
  server:
    #path: http://%s3_bucket_name%.s3-website-%s3_region%.amazonaws.com/%env%
    path: http://%s3_region%/%s3_bucket_name%/selfies/%env% # this one is working

使用s3_region的以下值:s3_region:s3-eu-west-1.amazonaws.com

转载注明原文:symfony – 使用SonataMediaBundle上传到AmazonS3 - 代码日志