Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

ruby on rails - AWS S3, Paperclip missing required :bucket option

I'm trying to use Paperclip and SWS S3 on Heroku to let users upload images.

I do not have my credentials stored in a yml file. I've followed the instructions on the Heroku page: https://devcenter.heroku.com/articles/paperclip-s3

But, when I try to run my app and upload an image I'm getting this message:

missing required :bucket option
Rails.root: /Users/scottsipiora/Sites/clycss

Application Trace | Framework Trace | Full Trace
app/controllers/instructors_controller.rb:63:in `block in update'
app/controllers/instructors_controller.rb:62:in `update'

The instructions don't mention anything about making a change in my controller. I have seen some examples telling me to put in something like:

In my model I have the following code:

class Instructor < ActiveRecord::Base
  attr_accessible :bio, :hometown, :name, :school, :sort_order, :started_sailing, :started_teaching, :photo
  has_attached_file :photo, styles: {
    thumb: '100x100>',
    square: '200x200#',
    medium: '300x300>'
  }
end

In my production.rb I have (obviously replacing my real credentials with mock credentials):

  config.paperclip_defaults = {
    :storage => :s3,
    :s3_credentials => {
      :bucket => ENV['bucket name'],
      :access_key_id => ENV['key_id'],
      :secret_access_key => ENV['access_key']
    }
  }

I've also created separate buckets for Production and Dev so things are cleaner.

Any ideas? I'm relatively new and this should be pretty easy.

Thanks in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you may have made the same mistake I did. In your production.rb file, do not edit the text to add your specific S3 keys. Just copy-paste the text directly as is listed in the tutorial.

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

Then, set the environmental variables AWS_BUCKET, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY as described by the author of the dev center article.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...