简体   繁体   中英

Rails Paperclip S3 - missing required :bucket option

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!

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"                        

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM