If I could spare anyone even a fraction of the time it took me to configure this properly I can only imagine the time saved, given the last two days of head pounding I’ve gone through to finally make this correctly work with the latest AWS SDK (v3.2.5).
So all that under the bridge, here’s a final config to have your images, and any (all) associated filters cached in your S3 buckets.
app/config/parameters.yml
parameters: # You probably don't want to use "latest" in a production environment... aws_sdk_version: latest aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY aws_s3_region: us-east-1 aws_bucket_name: YOUR_BUCKET_NAME # This isn't required for this config, but I use it everywhere, so.. aws_s3_base_url: 'https://s3.amazonaws.com'
app/config/config.yml
knp_gaufrette: stream_wrapper: protocol: litwicki adapters: images: aws_s3: service_id: litwicki.aws_s3 bucket_name: %image_bucket% options: create: true filesystems: images: adapter: images alias: images_filesystem liip_imagine: data_loader: stream.images filter_sets: litwicki_thumbnail: cache: avatars data_loader: litwicki.data_loader.litwicki_thumbnail quality: 75 filters: thumbnail: { size: [360, 640], mode: inbound } upscale: { min: [360, 640] } relative_resize: { widen: 640 }
/path/to/services.yml
note: you could also just include this in app/config/config.yml
services: litwicki.aws_credentials: class: Aws\Credentials\Credentials arguments: [%aws_access_key_id%, %aws_secret_access_key%] litwicki.aws_s3: class: Aws\S3\S3Client #factory_class: Aws\S3\S3Client #factory_method: 'factory' arguments: - #key: %aws_access_key_id% #secret: %aws_secret_access_key% region: %aws_s3_region% version: %aws_sdk_version% credentials: @litwicki.aws_credentials litwicki_litwicki_thumbnails.imagine.cache.resolver.amazon_s3: class: Liip\ImagineBundle\Imagine\Cache\Resolver\AwsS3Resolver arguments: - "@litwicki.aws_s3" - "%image_bucket%" tags: - { name: 'liip_imagine.cache.resolver', resolver: 'litwicki_thumbnails' } litwicki.liip_imagine.binary.loader.litwicki.data_loader.litwicki_thumbnail: class: "%liip_imagine.binary.loader.stream.class%" arguments: - 'litwicki://litwicki_thumbnails/' tags: - { name: 'liip_imagine.binary.loader', loader: 'litwicki.data_loader.litwicki_thumbnail' }
4 Comments
cameron · February 14, 2016 at 6:04 am
Thanks for the article, looking forward to trying this.
There’s also some good information on the Stream Loader for liipImagine on the symfony page:
http://symfony.com/doc/current/bundles/LiipImagineBundle/data-loader/stream.html
Paddy · June 28, 2016 at 6:30 am
Thanks for this useful article. Do you know what the final cached image paths should look like? I have a issue on GitHub here – https://github.com/liip/LiipImagineBundle/issues/735
Jake Litwicki · July 5, 2016 at 7:05 pm
Can you confirm that the
%s3_bucket%
parameter is properly set, and also that the bucket itself exists and has proper read/write permissions? If I remember correctly you’ll need to have those cache buckets created and permissions set in order for Liip to correctly send cached files there, otherwise it will fail.Angular + Symfony file upload with AWS S3 | JAKE LITWICKI · August 19, 2015 at 3:26 pm
[…] referencing my previous post on setting up Liip + Gaufrette + AwsS3 I’ll assume you’ve configured and set that up properly. Given that, you’d adjust […]