0

我有一個功能性symfony應用程序與奏鳴曲媒體。到現在爲止,我正在使用文件系統。但上傳的文件越來越大,我願意使用CDN來存儲這些文件(以避免內存分配問題)。sonata media-AWS CDN

我去了there但這個配置失敗。我有一個可用的cloudfront發行版,但在config.yml的sonata_media下無法識別選項「cloudfront」。

然後,我嘗試並使用了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: 

回答

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 
+0

感謝您的答覆。 如何在「there」示例代碼中的sonata_media.cdn下有「cloudfront」選項? –

+0

另一件事:我的IAM用戶具有完整的s3訪問權限,但當我嘗試提交我的奏鳴曲管理表單時,出現「無法寫入關鍵字」錯誤... –

+0

是該區域的關鍵正確嗎?它必須與創建存儲桶的位置相同。 – Udan