How to use Amazon S3 Bucket with Paperclip to store images in Rails3

Amazon S3 Online Service resized200 150x150
Social sharing


“S3 Bucket” is Amazon Simple Storage Service – a “highly durable and available store” and can be used to reliably store graphical and other applications contents such as media files, static assets and user uploads. It allows you to off-load your entire storage infrastructure. This feature facilitates better scalability, reliability, and speed than just storing files on the file-system.

It is an online storage web service offered by Amazon Web Services and provides storage through web services interfaces (REST, SOAP etc.)

Here is an example on how to use Amazon S3 with paperclip in Ruby on Rails applications.


  • In rails 3.x

Install aws-s3 gem by adding in Gemfile

gem 'aws-s3'

And run

Run “bundle install”


To get AWS S3 bucket ‘Access Key ID’ and ‘Secret Access Key’ go to the “”

Create s3.yml file under config directory and enter your Amazon S3 credentials

bucket: bucket-dev-name
access_key_id: xxxxx
secret_access_key: xxxxx
bucket: bucket-test-name
access_key_id: xxxxx
secret_access_key: xxxxx
bucket: bucket-prod-name
access_key_id: xxxxx
secret_access_key: xxxxx


Open your model file that would hold the attachment and modify it as follows

has_attached_file :photo,:styles =>{ :thumb => "100x100", :medium => "200x200", :large => "600x400" },:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",:path => ":attachment/:id/:style.:extension",:bucket => 'yourbucket'


In view, to display the image

Your recently viewed posts:

Jayadev Das - Post Author

Do what you do best in – that’s what I’ve always believed in and that’s what I preach. Over the past 25+ years (yup that’s my expertise ‘n’ experience in the Information Technology domain), I’ve been consulting to small, medium and large companies ‘About Web Technologies, Mobile Future as well as on the good-and-bad of tech. Blogger, International Business Advisor, Web Technology Expert, Sales Guru, Startup Mentor, Insurance Sales Portal Expert & a Tennis Player. And top of all – a complete family man!

    Contact Us

    We’d love to help & work with you

    When do you want to start ?

    Enter your email address to stay up to date with the latest news.
    Holler Box

    Orange Exit pop up

    Subscribe for the latest
    trends in web and
    mobile app development
    Holler Box

    Exit pop up

    Sad to see you leaving early...

    From "Aha" to "Oh shit" we are sharing everything on our journey.
    Enter your email address to stay up to date with the latest news.
    Holler Box