Rails Paperclip S3 - Missing Required: Bucket Option

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

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

The error I am getting is:

 ArgumentError at /attachments missing required :bucket option 

I tried this in my /environment/development.rb configuration:

  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 (move: 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!

+4
source share
1 answer

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

To do this, create a file in config / application.yml and put the following data into 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 reboot the server. Then you can 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" 
+4
source

Source: https://habr.com/ru/post/1501299/


All Articles