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

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

< 1 Minute Read


“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

, ,
Jayadev Das

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 ‘bout 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!

No Comments

Post A Comment

Exit pop up

Before You Go...!

Subscribe to Andolasoft Blog

Stay up to date with the latest techniques of web & mobile app development service tips and our SaaS and open source product news.
Holler Box