Spree 3.0.0使用S3 - 管理页面和正面页面的图像链接不正确

时间:2016-04-23 11:48:05

标签: amazon-s3 spree

我最近在Amazon CLI Elastic Beanstalk上运行了Spree 3.0.8。 我遇到了一个问题,我无法解决它2周。 我的Spree商业可以使用以下内容将产品图像上传到S3存储桶:

attachment_config = {

s3_credentials: {
    access_key_id: "XXXXXXXXXXX",
    secret_access_key: "gO7XXXXXXXXXX",
    bucket: "sirac-products"
},

storage:        :s3,
s3_headers:     { "Cache-Control" => "max-age=31557600" },
s3_protocol:    "https",
bucket:         "sirac-products",
url:            "s3-website-ap-southeast-2.amazonaws.com",

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 端

问题是管理员和正面的图片链接都不正确。  (图像链接使用s3.amazonaws.com而不是s3-ap-southeast-2.amazonaws.com)。

有人会帮我发布这个问题吗?

1 个答案:

答案 0 :(得分:1)

在您的spree配置文件中,尝试复制此代码并根据您进行修改(例如:存储桶名称,密钥ID和所有...)查看是否有效,请确保您输入的区域正确无误。您也可以在s3存储桶中检查

  

配置/初始化/ spree.rb

#--------------------------------------------
Spree.config do |config|
  config.admin_interface_logo = "logo.png" #don copy this


  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['ENV_BUCKET_NAME'],
  s3_host_name: "s3-us-west-2.amazonaws.com", #your region
  url:         "url",
  styles:      {
                 mini:   "60x76#",
                 small:  "270x340#", #totally depends how you are going to keep the styles
                 product:"670x844#",
                 large:  "700x881>"
               },

  path:        "/spree/:class/:id/:style/:basename.:extension",
  default_url: "/spree/products/:id/:style/:basename.:extension",
  default_style: "product",
  }
  attachment_config.each do |key,value|
  Spree::Image.attachment_definitions[:attachment][key.to_sym]=value
  end
end

这对我有用,希望能为你做同样的事情