SignatureNotFound 与 fog-aws 和 carrierwave

SignatureNotFound with fog-aws and carrierwave

我正在使用 carrierwave 和 fog-aws,同时将文件上传到 aws 并将 aws url 存储在我的本地数据库中 table.I 已经创建了 carrierwave.rb 文件来配置所有 fog- aws 凭据。

begin
 CarrierWave.configure do |config|                      # required
 config.storage = :fog

 config.fog_credentials = {
  :provider               => 'AWS',       # required
  :aws_access_key_id      => 'Key_id',       # required
  :aws_secret_access_key  => 'access_key',       # required
  :region                 => 'us-west-2'  # o\tional, defaults to 'us-east-1'
  # :fog                   => 'host',
  # :endpoint               => 'host'
 }
 config.fog_directory  = 'my-images-server' # required
 # see https://github.com/jnicklas/carrierwave#using-amazon-s3
 # for more optional configuration
 config.fog_public     = true   # optional, defaults to true

我的上传文件包含

class QueryUploader < CarrierWave::Uploader::Base
 storage :fog
 def store_dir
  base_dir = File.join(Rails.root, "public", "uploads")
  "#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
 end
 def cache_dir
  "/tmp/service-quep"
 end
 def extension_white_list
   %w(sql)
 end
end

我读了很多文章,从 2 天开始我就崩溃了,仍然找不到任何 solution.My 访问密钥没有 space 并且存储桶名称没有尾随 slash.Can 任何人都可以说出为什么

Expected(200) <=> Actual(403 Forbidden) excon.error.response :body => "\nSignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.YTUUYUDTDYJBKJNUFYD

错误来了。

看,在这个方法上你不需要写额外的代码因为 Rails 目录映射会自动就像你使用 "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 然后它会自动映射 /public/uploads/...

你的代码

def store_dir
    base_dir = File.join(Rails.root, "public", "uploads")
    "#{base_dir}/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

会是

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

你可以查看this gist this is great for working with Rails, CarrierWave and AWS, also you can check this