Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用Spree设置AmazonS3?_Ruby On Rails_Heroku_Amazon S3_Paperclip_Spree - Fatal编程技术网

Ruby on rails 如何使用Spree设置AmazonS3?

Ruby on rails 如何使用Spree设置AmazonS3?,ruby-on-rails,heroku,amazon-s3,paperclip,spree,Ruby On Rails,Heroku,Amazon S3,Paperclip,Spree,我试着在网上读了很多东西,但都没用。因此,我们需要一个具体的答案。如何配置S3以使用Spree? 我正在使用Spree 3.0.1和Rails 4.2.1 我将spree.rb设置为: Spree.config do |config| # Example: # Uncomment to override the default site name. # config.site_name = "Gazella Running Costumes" # config.logo

我试着在网上读了很多东西,但都没用。因此,我们需要一个具体的答案。如何配置S3以使用Spree? 我正在使用Spree 3.0.1和Rails 4.2.1

我将spree.rb设置为:

Spree.config do |config|
   # Example:
   # Uncomment to override the default site name.
  #  config.site_name = "Gazella Running Costumes"
  #  config.logo = "store/rungazella.png"

  #S3 configuration
  if Rails.env.production? then
       #production. Store images on S3.
       # development will default to local storage
      attachment_config = {
      s3_credentials: {
        access_key_id: ENV["S3_KEY"],
        secret_access_key: ENV["S3_SECRET"],
        bucket: ENV["S3_BUCKET"],
      },


      storage:        :s3,
      s3_headers:     { "Cache-Control" => "max-age=31557600" },
      s3_protocol:    "https",
      bucket:         ENV["S3_BUCKET"],

      path:          ":rails_root/public/:class/:attachment/:id/:style/:basename.:extension",
      default_url:   "/:class/:attachment/:id/:style/:basename.:extension",
      default_style: "product",
      }

      attachment_config.each do |key, value|
           Spree::Image.attachment_definitions[:attachment][key.to_sym] = value
      end
  end
Spree.user_class = "Spree::User"
end
我的档案也是

source 'https://rubygems.org'
gem 'rails', '4.2.1'
ruby '2.2.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
    gem 'byebug'
    gem 'web-console', '~> 2.0'
    gem 'spring'
end
gem 'spree', '3.0.1'
gem 'spree_gateway', github: 'spree/spree_gateway', branch: '3-0-stable'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
gem 'rails_12factor', group: :production
gem 'pg'
gem 'aws-sdk'

能否尝试从设置中删除路径:

path:“:rails\u root/public/:class/:attachment/:id/:style/:basename.:extension”,


当映像将存储在S3中时,有一个引用Rails根目录的
路径似乎很奇怪。

首先,您需要添加版本低于2.0的gem“aws sdk”:

gem 'aws-sdk', '< 2.0'
用这个宝石

 gem 'aws-sdk', '< 2.0'

首先从
spree中删除S3配置设置。rb
spree后端已在
常规设置=>图像设置=>启用S3
中具有此配置

嘿,您只需要从spree后端启用S3。在那里提供所需的基本细节。 在initilizer
paperclip.rb中添加以下行

if Rails.env.production?
    Paperclip.interpolates(:s3_eu_url) do |attachment, style|
      "#{attachment.s3_protocol}://#{Spree::Config[:s3_host_alias]}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
    end
    Paperclip::Attachment.default_options[:use_timestamp] = false
    Paperclip::Attachment.default_options[:s3_protocol] = "https"
end
您的附件Url应该是
:s3_eu_Url
,因为我们在initilizer中初始化了此Url的插值

我在这里找到了答案:

将gemfile
aws sdk
gem更改为:
gem-aws-sdk,<2.0


显然,这个问题是从更新版本的aws sdk开始的,因此您需要低于2.0的版本

你用回形针宝石来处理图像吗?是的,我用回形针。你有解决办法吗?我自己也在努力解决这个问题,在我正在进行的项目中,我发现S3不起作用,因为
Spree::Image
被重新打开,并且
path
url
选项也被设置在那里,这在初始值设定项中超过了这些设置。另外,从Spree 3.0.2开始,
aws sdk
必须是
<2.0
。希望这有帮助。但我在spree 3中找不到它。
spree.config do |config|
  attachment_config={
  s3_credentials: {
  access_key_id: ENV['AWS_ACCESS_KEY_ID'],
  secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
  bucket: ENV['ENV_BUCKET_NAME']
  },
  storage:     :s3,
  s3_headers:  {"Cache-Control"=>"max-age=31557600"},
  s3_protocol: "https",
  bucket:      ENV['S3_BUCKET_NAME'],
  url:         "url",
  styles:      {
                 mini:   "48x48>",
                 small:  "100x100>",
                 product:"240x240>",
                 large:  "600x600>"
               },
  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
if Rails.env.production?
    Paperclip.interpolates(:s3_eu_url) do |attachment, style|
      "#{attachment.s3_protocol}://#{Spree::Config[:s3_host_alias]}/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
    end
    Paperclip::Attachment.default_options[:use_timestamp] = false
    Paperclip::Attachment.default_options[:s3_protocol] = "https"
end