fahrio
fahrio

Reputation: 109

Ruby on Rails / Paperclip / AWS::S3::NoSuchBucket error

I installed the paperclip plugin and was able to use it locally. When I configured it to work with amazon S3 I keep getting the NoSuchBucket (The specified bucket does not exist) error. Paperclip documentation states that the bucket will be created if it doesn't exist but clearly something is going wrong in my case.

I first insalled aws-s3 gem (v0.6.2) then also installed right_aws gem (v1.9.0)

both have corresponding

config.gem "aws-s3", :lib => "aws/s3"
config.gem 'right_aws', :version => '1.9.0'

lines in environment.rb file

The code for the image.rb file with paperclip is as follows:

class Image < ActiveRecord::Base

    belongs_to  :work

    has_attached_file :photo, :styles => {:big => "612x1224>", :small => "180X360>", :thumb => "36x36#"},
                      :storage => 's3',
                      :s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV],   
                      :path => ":attachment/:id/:style/:basename.:extension",
                      :bucket => 'my-unique-image-bucket'

    attr_protected :photo_file_name, :photo_content_type, :photo_size

    validates_attachment_presence :photo
    validates_attachment_size :photo, :less_than => 3.megabytes
    validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png', 'image/gif']

end

Upvotes: 3

Views: 3801

Answers (5)

phil pirozhkov
phil pirozhkov

Reputation: 4900

It's not your case, but AWS doesn't allow upper case letters in bucket name and paperclip doesn't check that, failing in create_bucket.

Upvotes: 0

pdoherty926
pdoherty926

Reputation: 10349

In case anyone winds up here via google: I saw this same error when I mistakenly switched the order of the 2nd and 3rd parameters I was passing to AWS::S3::S3Object.store.

Upvotes: 0

hoopman
hoopman

Reputation: 11

it should create but the bucket but this was a bug at one point :

http://groups.google.com/group/paperclip-plugin/browse_thread/thread/42f148cee71a0477

i recently had this problem and it turned out to be the servers time was hugely off and s3 wouldnt allow any updates "that far in the future" or similar but the rails error was NoSuchBucket...confusing

..

Upvotes: 1

fahrio
fahrio

Reputation: 109

I have installed the s3fox plugin for firefox and created the bucket with the plugin. Now Paperclip works fine with S3 as the bucket identified is already created.

But I am still curious about paperclip's inability to create new buckets with the code above.

Upvotes: 0

Mike Buckbee
Mike Buckbee

Reputation: 6983

I'm not entirely sure this is it, but your loading of the s3_credentials is different than what I'm using on my production sites.

My config line is:

:s3_credentials => "#{RAILS_ROOT}/config/s3.yml"

Instead of

:s3_credentials => YAML.load_file("#{RAILS_ROOT}/config/s3.yml")[RAILS_ENV]

Upvotes: 3

Related Questions