【问题标题】:Rails Paperclip S3 ArgumentError (missing required :bucket option):Rails Paperclip S3 ArgumentError(缺少必需的 :bucket 选项):
【发布时间】:2013-09-14 05:31:55
【问题描述】:

我已经被这个问题困扰了很久,无法弄清楚出了什么问题。有很多人似乎有同样的问题,但我实际上找不到任何真正有效的答案。

生产.rb

  config.paperclip_defaults = {
  :storage => :s3,
  :s3_credentials => {
    :bucket => ENV['my bucket name is here'],
    :access_key_id => ENV['my key is here'],
    :secret_access_key => ENV['my secret key is here']
  }
}

游戏.rb

require 'aws/s3'

class Game < ActiveRecord::Base

attr_accessible  :swf, :swf_file_name, :name, :description, :category, :age_group, :dimension_x, :dimension_y, :image, :image_file_name, :feature_image, :feature_image_file_name, :developer, :instructions, :date_to_go_live, :date_to_show_countdown, :plays
has_attached_file :swf

has_attached_file :image

has_attached_file :feature_image

  def swfupload_file=(data)
    data.content_type =
MIME::Types.type_for(data.original_filename).first.content_type
    logger.warn("Data content type is: #{data.content_type}")
    self.file = data
  end

end

回形针.rb

Paperclip::Attachment.default_options[:url] = ':s3_domain_url'
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename'

【问题讨论】:

    标签: ruby-on-rails amazon-s3 paperclip


    【解决方案1】:

    这是我的回形针初始化的东西:

    Paperclip::Attachment.default_options.merge!({
        storage: :s3,
        s3_credentials: {
            access_key_id: ENV['S3_KEY'],
            secret_access_key: ENV['S3_SECRET'],
            bucket: "#{ENV['S3_BUCKET']}-#{Rails.env}"
            },
        url: ":s3_domain_url",
        path: "/:class/:attachment/:id_partition/:style/:filename"
        })
    

    这假设我们调用了三个环境变量设置,您猜对了... S3_KEY、S3_SECRET 和 S3_BUCKET。我做了一个小技巧,通过将 Rails.env 添加到存储桶变量中,我可以在每个环境中拥有不同的存储桶。

    您似乎在您的问题中表明您将存储桶的实际名称放在对 ENV 的引用中,这是行不通的。你应该把bucket的名字放在环境变量中,并以环境变量的名字作为key。

    我希望这会有所帮助。

    【讨论】:

    • 非常感谢!我查看的所有教程和代码都假设它们应该是实际名称的占位符。
    猜你喜欢
    • 1970-01-01
    • 2013-07-25
    • 2014-05-31
    • 2014-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多