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

二次信任 提交于 2019-12-14 03:49:26

问题


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:


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]



回答2:


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

..




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/1346906/ruby-on-rails-paperclip-awss3nosuchbucket-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!