Rails Paperclip S3 - missing required :bucket option

你离开我真会死。 提交于 2019-12-10 16:01:55

问题


I'm trying to use Amazon S3 for Paperclip attachments. First, I'm trying to get it to work in development environment on my iMac.

I have created the Amazon buckets = ndeavor-dev and ndeavor-pro. In the code below, I have substituted the bucket name and keys. I have the gem's paperclip and aws-sdk.

The error I get is:

ArgumentError at /attachments
missing required :bucket option

I have tried this in my config/environments/development.rb:

  config.paperclip_defaults = {
    :storage => :s3,
    :s3_protocol => 'http',
    :bucket => ENV['AWS_BUCKET'],
    :s3_credentials => {
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
  }

And I tried this (moving the :bucket):

  config.paperclip_defaults = {
    :storage => :s3,
    :s3_protocol => 'http',
    :s3_credentials => {
      :bucket => ENV['AWS_BUCKET'],
      :access_key_id => ENV['AWS_ACCESS_KEY_ID'],
      :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
    }
  }

Thanks for the help!


回答1:


Like dcro says, you need to set the AWS_BUCKET environment variable properly.

To do this, create a file at config/application.yml and put the following in it, using your Amazon credentials:

AWS_ACCESS_KEY_ID: "whatever_the_key_is"
AWS_SECRET_ACCESS_KEY: "whatever_the_secret_is"
AWS_BUCKET: "ndeavor-dev"

Then restart your server. You'll then be able to use your models something like this:

 has_attached_file :attachment                                                                 ,
                      :storage        => :s3                                                 ,
                      :s3_credentials => {:bucket            => ENV['AWS_BUCKET'           ],
                                          :access_key_id     => ENV['AWS_ACCESS_KEY_ID'    ],
                                          :secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']},
                      :s3_protocol    => "https"                                             ,
                      :s3_host_name   => "s3-eu-west-1.amazonaws.com"                        


来源:https://stackoverflow.com/questions/18699300/rails-paperclip-s3-missing-required-bucket-option

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