If ever you'll find yourself having problems with displaying a paperclip attachment stored in a Non-US AWS S3 bucket, please try this solution.

#Gemfile
gem 'paperclip' #3.5.1
gem 'rmagick' #2.13.2
gem 'aws-sdk' #1.18.0
gem 'rails_admin' #0.0.1

So, the trouble was, the image doesn't display on a show and edit page because it kept calling the default endpoint of s3.amazonaws.com.

Solution:

  • Install dot_env gem to isolate all constants and setup related data
    • gem install dot_env
  • Create your .env file as such, using the suggested AWS constants:

    AWSACCESSKEY_ID: accesskeyid

    AWSSECRETACCESS_KEY: mysecretaccesskey

    AWSDEFAULTREGION: ap-southeast-2

    BUCKET: mybucketname

  • Your default region is the region where you assigned your bucket to. You can find the list of regions here: Regions and Endpoints. Also take note of the endpoint here.

  • Append a config for paperclip inside your environment file (config/environments/development.rb, etc.) where your s3_host_name is your endpoint found in the Regions and Endpoints AWS document.

    config.paperclipdefaults = { :storage => :s3, :s3credentials => { :bucket => ENV['BUCKET'], :accesskeyid => ENV['AWSACCESSKEYID'], :secretaccesskey => ENV['AWSSECRETACCESSKEY']}, :s3hostname => 's3-ap-southeast-2.amazonaws.com'}

  • Modify your rails_admin.rb. If you have a model that has an image field which is a Paperclip object, you can do this for the display (aside from simply using thumb_method :style)

    field(:image) do pretty_value do bindings[:view].tag(:img, { :src => bindings[:object].image.url(:style) }) end end

I spent quite some time experimenting with the correct settings.  I hope this saves someone else's time! :)