Skip to main content

Paperclip uploading files (or)images to amazon s3 for Ruby on rails?

Paperclip uploading files (or)images to amazon s3 for Ruby on rails?

1)Add a gem
'gem 'aws-sdk'

2)bundle install

3)app/models/profile.rb-----Model add this code
has_attached_file :image,
                   :storage => :s3,
                   :bucket => "yyyyyy",
                   :s3_permissions => "public-read",
                   :path => "profiles/:id/:basename.:extension",
                   :s3_credentials => {
                   :access_key_id => "xxxxxxxxxxxxx",
                   :secret_access_key => "xxxxxxxxxxx"
                  
    }
validates_attachment :file,:content_type => { :content_type => ["image/jpg", "image/gif", "image/png","application/pdf"] }

4)add coe for controller
def profile_image_create
 @profile = Profile.create(:file => params[:file])
end

===========Amazon s3 create a bucket=========
http://aws.amazon.com/s3/
Go to home page => click on create bucket button
Go to header right side tab => security credentails and create the accesskey and secret key for amazon

link: http://www.blitztheory.com/direct-upload-with-s3_direct_upload/

Comments