Amazon’s S3 european buckets and Paperclip in Rails 3

Paperclip issue with Amazon’s S3 european buckets – solved

Finally I have found a solution for the well known problem of thoughtbot’s Paperclip and Amazon’s S3 EU buckets.

    Paperclip configuration for Amazon S3

  1. First of all you have to define the has_attached_file class method inside your class. I have something like:
    class Photo  < ActiveRecord::Base
        has_attached_file :img, :styles => {
                :thumb => ["35x35#", :jpg],
                :medium => ["150x", :jpg],
                :original => ["650x", :jpg]
        :storage => :s3,
        :s3_credentials => "#{Rails.root}/config/amazon_s3.yml",
        :s3_protocol => "https",
        :path => ":class/:id/:basename_:style.:extension",
        :bucket => "your_bucket_name_here",
        :urlĀ  => ":s3_eu_url"
  2. Paperclip initializer to handle Amazon S3 url’s

  3. Next create an initializer (/config/initializers/paperclip.rb) and inside define a Paperclip interpolation for the :s3_eu_url (paperclip uses this to construct the url of the image when you display it).
    Paperclip.interpolates(:s3_eu_url) do |att, style|
  4. AWS patch for setting the correct Amazon’s S3 EU url

  5. Now that you have correctly defined the urls that Paperclip generates, you have to explicitly change the default host that Paperclip connects to when you uploading an image to Amazon’s S3. Well, this is not a Paperclip issue at all. Paperclip uses the infamous AWS::S3 when it connects to Amazon, so the issue comes from misconfiguring the AWS. Inside the same initializer put the following code
    module AWS
        module S3
            DEFAULT_HOST = ""

Now you have a fully working Amazon S3 backed image (and not only) uploading system working in Rails 3.0

13 Comments Amazon’s S3 european buckets and Paperclip in Rails 3

  1. Kevin

    Great, I’ll be looking to give this solution a try over the weekend. I had recently switched back to a US bucket because I had other things to develop.

  2. Jules

    Dude! – This works.

    Thank you so much.

    Took a bit of finding on google after playing around with a few other solutions. Let’s hope this gets up the google rankings so other people can find it.

  3. Axel

    Hi Gerry,

    thx for this beautiful page:) This is good stuff and my site is working well with EU-Buckets…

    Have a good time..


  4. Claire

    Hi Gerry,

    Thanks it really works.
    I also tried adding this to the environment instead.


    – Claire

  5. Dean

    Excellent, thanks for this!
    For a moment there I thought I was going to have to upload everything onto a US bucket.
    Thanks! :)


Leave a Reply to Claire Cancel reply

Your email address will not be published. Required fields are marked *