我正在尝试在我的spree rails app中使用aws s3。
以下是我尝试设置的方法。
我gem 'aws-sdk', '< 2.0'
中有Gemfile
。
以下是初始值设定项下的spree.rb
。
Spree.config do |config|
end
Spree.user_class = "Spree::User"
attachment_config = {
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
storage: :s3,
s3_headers: { "Cache-Control" => "max-age=31557600" },
s3_protocol: "https",
bucket: ENV['S3_BUCKET_NAME'],
url: ":s3_domain_url",
styles: {
mini: "48x48>",
small: "100x100>",
product: "240x240>",
large: "600x600>"
},
path: "/:class/:id/:style/:basename.:extension",
default_url: "/:class/:id/:style/:basename.:extension",
default_style: "product"
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end
当我运行时,我正在
Spree :: Home#index
中的ArgumentError
missing required :bucket option
我不确定缺少什么,有人可以指出吗?
答案 0 :(得分:0)
仔细检查您是否在环境中设置了S3_BUCKET_NAME
。
然后你的spree.rb看起来应该是这样的
Spree.config do |config|
end
Spree.user_class = "Spree::User"
attachment_config = {
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['S3_BUCKET_NAME']
},
storage: :s3,
s3_headers: { "Cache-Control" => "max-age=31557600" },
s3_protocol: "https",
styles: {
mini: "48x48>",
small: "100x100>",
product: "240x240>",
large: "600x600>"
},
path: "/:class/:id/:style/:basename.:extension",
default_url: "/:class/:id/:style/:basename.:extension",
default_style: "product"
}
attachment_config.each do |key, value|
Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
end