views:

1104

answers:

4

Hello;

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
+1  A: 

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]
Mike Buckbee
The actual plugin loads the YAML file, you shouldn't.
Garrett
Tried your way of loading the YAML file, it still doesnt work. There is probably nothing wrong with the credential file as it loads fine and gives different errors when it couldnt load or any of the keys are wrong.
fahrio
Have you created the bucket manually? (Using S3Fox, Transmit, or S3Hub) and then tried uploading?
Mike Buckbee
A: 

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.

fahrio
I don't know, some aspects of using S3 still seem very flaky to me and it is often hard to determine which system is at fault. For example "directory" structures (keys with slashes in them) often don't seem to work between client apps and I've even had some wonky permission issues with S3. That being said, it is still a great service and I rely on it, but it is necessary to test out your tool chain thoroughly.
Mike Buckbee
A: 

I was having the exact problem. I downloaded s3fox and created the bucket manually and boom, it works. Thanks so much. I was loosing my marbles over it.

tonywok
A: 

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

..

hoopman