【问题标题】:Set up aws s3 for image uploads with spree设置 aws s3 以使用 spree 上传图片
【发布时间】:2016-03-09 06:24:03
【问题描述】:

我正在尝试在我的 spree rails 应用程序中使用 aws s3。

这是我尝试设置的方法。

我的Gemfile 中有gem 'aws-sdk', '< 2.0'

下面是我的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 中的参数错误

missing required :bucket option

我不确定缺少什么,有人可以指出吗?

【问题讨论】:

    标签: ruby-on-rails ruby amazon-web-services amazon-s3 spree


    【解决方案1】:

    仔细检查您是否在您的环境中设置了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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 2018-07-11
      • 2018-03-02
      相关资源
      最近更新 更多