5

I'm wondering how to wrap aws php sdk (aws/aws-sdk-php) within Symfony2 in order to use as cdn with SonataMediaBundle.

My current sonata confuguration:

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%

But I receive an error: Attempted to load class "AmazonS3" from the global namespace.

peter
  • 147
  • 2
  • 13
  • My composer dependencies: `"aws/aws-sdk-php": "^3.0", "knplabs/knp-gaufrette-bundle": "*@dev"` – peter Aug 20 '15 at 09:36

2 Answers2

2

Apparently, playing with the config file is the right thing to do, in this case, we fixed our issue this way:

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

With the following value for s3_region: s3_region: s3-eu-west-1.amazonaws.com

GeoffreyB
  • 1,791
  • 4
  • 20
  • 36
1

Try to use https://packagist.org/packages/amazonwebservices/aws-sdk-for-php if you use sonata-project/media-bundle <= 2.3.3.

As you can see at packagist https://packagist.org/packages/sonata-project/media-bundle or at latest release's composer.json https://github.com/sonata-project/SonataMediaBundle/blob/2.3.3/composer.json#L37 it requires/suggests old amazonwebservices/aws-sdk-for-php: ~1.5 but not new aws/aws-sdk-php.

New aws/aws-sdk-php is only required by dev-master version of https://packagist.org/packages/sonata-project/media-bundle.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
igormukhingmailcom
  • 465
  • 1
  • 6
  • 9
  • As you see, gaufrette also supports that legacy package: https://github.com/KnpLabs/Gaufrette/blob/master/composer.json#L30 – igormukhingmailcom Aug 22 '15 at 12:53
  • Thank you Igor. I updated my composer with requested amazon SDK ("amazonwebservices/aws-sdk-for-php": "1.5.*"). I tried it already before but I had another issue. Curl is calling a bad url: https://bucket_name.region@, something is missing and I can't see why. [{"message":"cURL resource: Resource id #791; cURL error: couldn't connect to host at :443 (cURL error code 7). – peter Aug 24 '15 at 08:19