奏鸣曲媒体 - AWS CDN

时间:2016-05-23 15:41:15

标签: symfony amazon-s3 sonata-admin amazon-cloudfront sonata-media-bundle

我有一个带有奏鸣曲媒体的功能性symfony应用程序。直到现在,我正在使用文件系统。但是上传的文件越来越大,我愿意使用CDN来存储这些文件(以避免内存分配问题)。

我去了there但这个配置失败了。我有一个有效的云端分布,但选项" cloudfront"在config.yml中的sonata_media下无法识别。

然后,我尝试使用了S3存储桶。配置看起来不错但在我在sonata_admin中提交上传表单后,收到一条错误消息:"无法写入密钥" ...

我的IAM用户拥有完整的s3访问权限,并且存储桶已公开。

这是我的配置:

sonata_media:
db_driver: doctrine_orm
class:
    media:              Application\Sonata\MediaBundle\Entity\Media
    gallery:            Application\Sonata\MediaBundle\Entity\Gallery
    gallery_has_media:  Application\Sonata\MediaBundle\Entity\GalleryHasMedia         Application\Sonata\ClassificationBundle\Entity\Category
    default_context: default
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr
providers:

    #     allowed_mime_types: ['application/pdf', 'application/x-pdf', 'application/rtf', 'text/html', 'text/rtf', 'text/plain', 'video/mp4']

    file:
        service:    sonata.media.provider.file
        resizer:    false
        filesystem: sonata.media.filesystem.local
        cdn:        sonata.media.cdn.cloudront
        generator:  sonata.media.generator.default
        thumbnail:  sonata.media.thumbnail.format
        allowed_extensions: ['pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pttx', 'odt', 'odg', 'odp', 'ods', 'odc', 'odf', 'odb', 'csv', 'xml', 'mp4']
        allowed_mime_types: ['application/pdf', 'application/x-pdf', 'application/rtf', 'text/html', 'text/rtf', 'text/plain', 'video/mp4', 'video/webm']

    image:
        service:    sonata.media.provider.image
        resizer:    sonata.media.resizer.simple # sonata.media.resizer.square
        filesystem: sonata.media.filesystem.s3
        cdn:        sonata.media.cdn.server
        generator:  sonata.media.generator.default
        thumbnail:  sonata.media.thumbnail.format
        allowed_extensions: ['jpg', 'png', 'jpeg']
        allowed_mime_types: ['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png']

    youtube:
        service:    sonata.media.provider.youtube
        resizer:    sonata.media.resizer.simple
        filesystem: sonata.media.filesystem.s3
        cdn:        sonata.media.cdn.server
        generator:  sonata.media.generator.default
        thumbnail:  sonata.media.thumbnail.format
        html5: false

    dailymotion:
        service:    sonata.media.provider.dailymotion
        resizer:    sonata.media.resizer.simple
        filesystem: sonata.media.filesystem.s3
        cdn:        sonata.media.cdn.server
        generator:  sonata.media.generator.default
        thumbnail:  sonata.media.thumbnail.format
contexts:
    default:  # the default context is mandatory
        download:
            strategy: sonata.media.security.forbidden_strategy
            mode: http
        providers:
            - sonata.media.provider.dailymotion
            - sonata.media.provider.youtube
            - sonata.media.provider.image
            - sonata.media.provider.file

        formats:
            small: { width: 100 , quality: 70}
            big:   { width: 500 , quality: 70}

cdn:
    server:
        path: %s3_bucket_path%/uploads/media/

    #cloufront: ~
    #     path: http://%cloudfront_domain%.cloudfront.net/uploads/media
    #     distribution_id: %cloudfront_id%
    #     key: %cloudfront_key%
    #     secret: %cloudfront_secret%

filesystem:
    local:
        directory:  %kernel.root_dir%/../web/uploads/media
        create:     false

    s3:
        bucket: %bucket_name"
        accessKey: %access_key%
        secretKey:%secret_key%
        region: 

1 个答案:

答案 0 :(得分:0)

去“那里”是正确的,正确的配置应该是这样的:

cdn:
    server:
        path: http://%bucketname%.s3.amazonaws.com/blablafolder

filesystem:
    s3:
        bucket: %bucketname%
        accessKey: %aws_access%
        secretKey: %aws_secret%
        create: false
        region: us-east-1
        storage: standard
        acl: public