AWS S3,Paperclip 缺少必需的 :bucket 选项 [英] AWS S3, Paperclip missing required :bucket option

查看:28
本文介绍了AWS S3,Paperclip 缺少必需的 :bucket 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Heroku 上使用 Paperclip 和 SWS S3 来让用户上传图片.

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

我没有将我的凭据存储在 yml 文件中.我已按照 Heroku 页面上的说明进行操作:https://devcenter.heroku.com/articles/paperclip-s3

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

在我的 production.rb 中,我有(显然用模拟凭据替换了我的真实凭据):

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.

提前致谢.

推荐答案

我想你可能犯了和我一样的错误.在您的 production.rb 文件中,请勿编辑文本以添加您的特定 S3 密钥.只需按照教程中列出的内容直接复制粘贴文本即可.

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']
  }
}

然后,按照开发中心文章作者的描述设置环境变量 AWS_BUCKET、AWS_ACCESS_KEY_ID 和 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.

这篇关于AWS S3,Paperclip 缺少必需的 :bucket 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆