AWS S3, Paperclip missing required :bucket option

后端 未结 5 576
囚心锁ツ
囚心锁ツ 2020-12-06 05:09

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 t

相关标签:
5条回答
  • 2020-12-06 05:22

    Do heroku config to check your environment variables.

    Normally they are all caps and have underbars instead of spaces.

    If it is not set, you should set the environment variable with

    heroku config:add BUCKET_NAME=my_bucket_name
    

    Update your code:

    :bucket => ENV['BUCKET_NAME'],
    

    Heroku reference

    0 讨论(0)
  • 2020-12-06 05:23

    Scott, sorry if there was any confusion here.

    I am the author of the Dev Center article. As B Seven stated above the AWS Config Vars need to be set on the Heroku application.

    Heroku has recently updated their documentation (https://devcenter.heroku.com/articles/config-vars#example) and set is preferred over add going forward.

    
    $ heroku config:set AWS_BUCKET=your_bucket_name
    $ heroku config:set AWS_ACCESS_KEY_ID=your_access_key_id
    $ heroku config:set AWS_SECRET_ACCESS_KEY=your_secret_access_key
    
    
    0 讨论(0)
  • 2020-12-06 05:31
    • Insert into schema.rb table "instructors" this line
    create_table "instructors" do |t|
        ...
        t.string   "bucket"
    end
    
    • Add to controller @instructor[:bucket] = ENV['S3_BUCKET_NAME']
    • Run "rake db:setup"
    0 讨论(0)
  • 2020-12-06 05:34

    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.

    0 讨论(0)
  • 2020-12-06 05:45

    Make sure you restart your CLI of choice when setting values with environment variables. Don't be like me and set up Paperclip and AWS correctly with ENV variables and then waste a bunch of time on Google only to fix the issue by quitting and reopening Terminal.

    0 讨论(0)
提交回复
热议问题