我已经被困在这个问题上很多年了,不知道出了什么问题。有很多人似乎有同样的问题,但我实际上找不到任何真正有效的答案。
生产.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'
最佳答案
这是我的回形针初始化内容:
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 的引用中,这是行不通的。您应该将存储桶的名称放入环境变量中,并使用环境变量的名称作为键。
我希望这会有所帮助。
关于ruby-on-rails - Rails Paperclip S3 ArgumentError(缺少必需的 :bucket option):,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794779/