[英]AWS S3, Paperclip missing required :bucket option
我正在嘗試在Heroku上使用Paperclip和SWS S3來讓用戶上傳圖像。
我沒有將憑據存儲在yml文件中。 我按照Heroku頁面上的說明操作: https : //devcenter.heroku.com/articles/paperclip-s3
但是,當我嘗試運行我的應用程序並上傳圖像時,我收到此消息:
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'
說明中沒有提到有關在我的控制器中進行更改的任何內容。 我看到一些例子告訴我要加入類似的東西:
在我的模型中,我有以下代碼:
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
在我的production.rb中我(顯然用模擬憑證替換了我的真實憑證):
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['bucket name'],
:access_key_id => ENV['key_id'],
:secret_access_key => ENV['access_key']
}
}
我還為Production和Dev創建了單獨的存儲桶,因此事情更清晰。
有任何想法嗎? 我比較新,這應該很容易。
提前致謝。
我想你可能犯了同樣的錯誤。 在您的production.rb文件中,不要編輯文本以添加特定的S3密鑰。 只需按照教程中列出的方式直接復制粘貼文本即可。
#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']
}
}
然后,按照開發人員中心文章的作者所述設置環境變量AWS_BUCKET,AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY。
做heroku config
來檢查你的環境變量。
通常它們都是帽子並且有下墊而不是空格。
如果未設置,則應使用設置環境變量
heroku config:add BUCKET_NAME=my_bucket_name
更新你的代碼:
:bucket => ENV['BUCKET_NAME'],
斯科特,對不起,如果這里有任何混淆。
我是開發中心文章的作者。 正如上面提到的B Seven所述,需要在Heroku應用程序上設置AWS Config Vars。
Heroku最近更新了他們的文檔( https://devcenter.heroku.com/articles/config-vars#example ),並且set
比首先add
受歡迎。
$ 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
在使用環境變量設置值時,請確保重新啟動CLI。 不要像我一樣使用ENV變量正確設置Paperclip和AWS,然后在Google上浪費大量時間,以通過退出並重新打開終端來解決問題。 😞
create_table "instructors" do |t| ... t.string "bucket" end
@instructor[:bucket] = ENV['S3_BUCKET_NAME']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.