gpt4 book ai didi

ruby-on-rails - 如何在 Spree-2-2-stable 上使用 Amazon S3

转载 作者:行者123 更新时间:2023-12-04 06:00:32 26 4
gpt4 key购买 nike

我需要在 Amazon S3 上配置我的图像,但是当我在 Spree2-2-stable 版本下尝试这样做时,我意识到这个配置是离开了管理面板。

我在某处读到此配置会产生一些问题,因此在 2-2 时将其删除。但我认为该功能仍在以某种方式工作。

当我尝试将这些配置添加到我的 config/initialize/spree.rb 时,我收到一个错误,因为这些首选项不再存在。

preference :s3_access_key, :string
preference :s3_bucket, :string
preference :s3_secret, :string

这些偏好在 2-1-stable 上找到,但在 2-2-stable 上找不到

https://github.com/spree/spree/blob/2-1-stable/core/app/models/spree/app_configuration.rb https://github.com/spree/spree/blob/2-2-stable/core/app/models/spree/app_configuration.rb

有什么方法可以让它与 Heroku 一起使用吗?

最佳答案

这是 Spree 的更改提交和一些关于如何进行配置更改的说明。 https://github.com/spree/spree/commit/b1d6c5e4b9801d888cc76c05116b814945122207

我的理解是您仍然可以使用回形针管理上传到 S3,我已经使用他们的说明成功完成了。但是,我在正确配置 S3 上的保存路径时遇到了问题。这可能会让你开始......在环境配置文件中放置以下内容:

  # Paperclip configs
config.paperclip_defaults = {
:storage => :s3,
:bucket => ENV['S3_BUCKET_NAME'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}

我将环境变量用于 S3 凭据,因此您的很可能会有所不同。这段代码使将文件上传到 S3 变得可行,就像我说的那样,我不能在上传时强制使用特定的文件路径。希望对您有所帮助。

编辑 - 附加信息:

我将以下内容添加到 spree.rb 初始化程序以定义自定义上传路径和自定义 url 路径。

# S3 upload path and url path configuration
Spree::Image.attachment_definitions[:attachment][:path] = 'products/:id/:style/:basename.:extension'
Spree::Image.attachment_definitions[:attachment][:url] = 'products/:id/:style/:basename.:extension'

要更改默认上传大小,您可以覆盖 Spree 图像装饰器模型。所以在app/models下添加一个spree目录,添加一个名为image_decorator.rb的文件。然后,您可以使用以下方法控制尺寸:

Spree::Image.class_eval do
attachment_definitions[:attachment][:styles] = {
:mini => '48x48>', # thumbs under image
:small => '350x700>', # images on category view
:product => '1024x768>', # full product image
:large => '600x600>' # light box image
}
end

查看此页面了解详情 --> http://guides.spreecommerce.com/developer/logic.html

总而言之,您可以通过更新环境初始化器、Spree 初始化器并覆盖 spree image_decorator 模型来完成所有常规图像/S3 配置。

关于ruby-on-rails - 如何在 Spree-2-2-stable 上使用 Amazon S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21756596/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com