Amazon S3 and Paperclip on Rails 3
I previously posted about Using Amazon S3 with Paperclip. This post will talk about same topic. But this time for Rails 3.
gem 'aws-s3'
and run
bundle install
development: bucket: bucket-dev access_key_id: xxx secret_access_key: xxx test: bucket: bucket-test access_key_id: xxx secret_access_key: xxx production: bucket: bucket-pro access_key_id: xxx secret_access_key: xxx
#paperclip
has_attached_file :photo,
:styles => {
:thumb=> "100x100#",
:small => "400x400>" },
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/:style/:id/:filename"
That’s it! Simple isn’t it.
links that might help
17 Comments
→






I’ve used Uploadify and paperclip in Rails3 and I’m getting this error -
AWS::S3::NoSuchBucket (The specified bucket does not exist).
My s3.yml file is
————————————————–
development:
bucket: bucket-dev
access_key_id: ###
secret_access_key: ###
test:
bucket: bucket-test
access_key_id: ###
secret_access_key: ###
production:
bucket: bucket-pro
access_key_id:###
secret_access_key: ###
————————————————–
and the model has -
————————————————–
has_attached_file :photo,
:storage => :s3,
:s3_credentials => “#{::Rails.root.to_s}/config/s3.yml”,
:path => “/:style/:filename”,
:styles => {:medium => “300×300>”,:thumb => “100×100>”}
————————————————–
what should I do?
Hello safalmj, you should create the buckets on Amazon S3 manually as far as I know, have you created the buckets (bucket-pro, bucket-test, bucket-dev)
Hi, dkberktas. Thanks a lot. Its working now. I used the bucket name that was previously created by my company.
Hi dkberktas. I have one more issue. My model looks like this –
- – - – - – - – - – – - -
has_attached_file :photo,
:styles => {:medium => “300×300>”,:thumb => “100×100>”},
:storage => :s3,
:s3_credentials => “#{RAILS_ROOT}/config/s3.yml”,
:path => “/:style/:id/:filename”
- – - – - – – - – - – – -
When I push my image file to Amazon S3, the file is saved inside three folders: (1) thumb, (2) original and (3) medium. I don’t want ‘original’ folder . I haven’t specified it inside model’s :styles{ } either. How do I prevent this ‘original’ folder from being saved in s3? Do I need to change any configuration with paperclip or model?
I think only way to do it to define your own original style, so that paperclip override its own original. If you find any other way, just let me know.
Yeap… That seems to work.
This was great, thanks for the quick overview! Rails and it’s community continue to amaze me
Major props my man, this got me (a rails newbie) up and running in no time!
Thx, saved me at least a few hours. I got paperclip an S3 running under 5 minutes.
won’t work for me… getting an error at the #{ROOT_PATH} hash. gah
@JP: When using Rails 3.1.x use “#{Rails.root}/config/s3.yml” instead.
Thank you, this was very helpful!
Perfect! Thank you.
I have created storage module for Paperclip that uses ‘aws-sdk’ gem. Works well, using it in production projects myself.
https://github.com/igor-alexandrov/paperclip-aws
Hello.
I need to connect to the webservice of Amazon to get the info of books by ISBN. I have already signed up in Amazon S3, but i don`t know which gems I need and which is the name of the webservice.
Do you know any note to do this? I understand this article is to store files in Amazon…
Tnaks