【问题标题】:Spree 3.0.0 use S3 - image links are incorrect for both admin and front side pagesSpree 3.0.0 使用 S3 - 管理页面和前端页面的图像链接都不正确
【发布时间】:2023-04-10 11:45:02
【问题描述】:

我最近下载了在 Amazon CLI Elastic Beanstalk 上运行的 Spree 3.0.8。 我遇到了一个问题,我无法解决 2 周。 我的 Spree Commerce 能够使用以下方法将产品图片上传到 S3 存储桶:

附件配置 = {

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 |key, value| Spree::Image.attachment_definitions[:attachment][key.to_sym] = value 结束

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

有人能帮我解决这个问题吗?

【问题讨论】:

    标签: amazon-s3 spree


    【解决方案1】:

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

    config/initializers/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
    

    这对我有用,希望对你也一样

    【讨论】:

    • 谢谢。它现在正在工作。您的解决方案为我节省了大量时间。希望您的回答也能对其他人有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 2013-04-04
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    • 2020-01-07
    • 2017-02-13
    相关资源
    最近更新 更多