Store your Spree Images on S3

Currently (>= 2-2-stable) the Spree backend does not give you the option anymore to configure s3 for image storage.

In this post I will show you how to make it happen.

Start with adding AWS-SDK to your gemfile with: gem 'aws-sdk', '~> 1.61.0', then install the gem by running bundle install. Note: make sure you use the aws-sdk v1 and not the v2 release since this is not compatible currently with the Spree setup.

When that's done you need to configure Spree to use s3. You can add an initializer or just use the spree.rb initializer located at config/intializers/spree.rb.

Note that I use the url: ":s3_domain_url" setting, this enabled the DNS lookup for your images without specifying the specific zone endpoint. You need to use a bucket name that makes a valid subdomain. So do not use dots if you are planning on using the DNS lookup config.

Updated: Thank you Jeff Dutil, who pointed me to the :class option for the default_url and default_style