轨道载波/ S3签名不匹配。私钥错误



我正在尝试使载波与S3一起工作,而我得到的签名则无法匹配错误。奇怪的是,看起来CarrierWave并没有发送正确的秘密键。在错误中,该帖子以:

给出。
"Authorization"=>"AWS AKIAIOLWQKSJFH6E3I5Q:vKgyAw2z4c8zzqGWoxLUbw7I5oI="

我认为应该是我的publickey:私人关键。问题是vkgyaw2z4c8zzqgwoxlubw7i5oi =不是我存储在fog.rb中的私钥。是对的吗?

任何帮助将不胜感激。

请求/响应:

 request => {:chunk_size=>1048576, :connect_timeout=>60, :headers=>{"Content-Length"=>1557, "Content-Type"=>"image/
gif", "x-amz-acl"=>"public-read", "Date"=>"Wed, 24 Oct 2012 12:45:17 +0000", "Authorization"=>"AWS AKIAIOLWQKSJFH6E3
I5Q:vKgyAw2z4c8zzqGWoxLUbw7I5oI=", "Host"=>"s3.amazonaws.com:443"}, :instrumentor_name=>"excon", :mock=>false, :nonb
lock=>true, :read_timeout=>60, :retry_limit=>4, :ssl_ca_file=>"/home/tim/.rvm/gems/ruby-1.9.3-p194/gems/excon-0.16.5
/data/cacert.pem", :ssl_verify_peer=>true, :write_timeout=>60, :host=>"myeasybnb.s3.amazonaws.com", :host_port=>"s3.
amazonaws.com:443", :path=>"/images%2Fb1bb6639-dc08-4981-9a9b-7175093ac970.gif", :port=>"443", :query=>nil, :scheme=
>"https", :body=>#<File:/home/tim/Dropbox/myeasybnb/tmp/uploads/20121024-0845-20225-1170/240x240.gif>, :expects=>200
, :idempotent=>true, :method=>"PUT"}
  response => #<Excon::Response:0xa7a1098 @body="<?xml version="1.0" encoding="UTF-8"?>n<Error><Code>SignatureD
oesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your
 key and signing method.</Message>

fog.rb:

CarrierWave.configure do |config|
  config.fog_credentials = {
    :provider               => 'AWS',       # required
    :aws_access_key_id      => 'AKIAIOLWQKSJFH6E3I5Q',       # required
    :aws_secret_access_key  => '[my secret key]'      # required
  }
  config.fog_directory  = 'myeasybnb'                             # required
  config.fog_public     = true                                   # optional, defaults to true
end

uploader.rb:

# encoding: utf-8
class PhotoUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick
  # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
   include Sprockets::Helpers::RailsHelper
   include Sprockets::Helpers::IsolatedHelper
  # Choose what kind of storage to use for this uploader:
  # storage :file
   storage :fog
  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "images"
  end
  # Provide a default URL as a default if there hasn't been a file uploaded:
class MyUploader < CarrierWave::Uploader::Base
  def default_url 
     asset_path("seeds/" + [version_name, "default.png"].compact.join('_'))
  end
end
  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #

  # Create different versions of your uploaded files:
  process :convert => 'jpg'
  version :sidecarousel, :if => :is_side_carousel? do
      process :resize_to_fit => [2000,1000]
  end
    version :thumbnail, :if => :is_thumbnail? do
       process :resize_to_fill => [240,240]        
    end
    version :linetext, :if => :is_line? do
         process :resize_to_fill => [400,200]
    end
    version :carousel, :if => :is_carousel? do
      process :resize_to_fit => [2200, 1000]
    end  
    version :phone do
      process :resize_to_fit => [900,900]
    end
  # def scale(width, height)
  #   # do something
  # end


  def is_side_carousel? photo
    model.location == 1
  end
  def is_thumbnail? photo
  model.location == 2
  end
  def is_line? photo
    model.location == 3
  end
  def is_carousel? photo
    model.location == 4
  end
  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
 def filename
    file.nil? ?  @filename = nil : @filename = "#{secure_token}.#{file.extension}" 

 end 
    def secure_token
    var = :"@#{mounted_as}_secure_token"
    model.instance_variable_get(var) or model.instance_variable_set(var, SecureRandom.uuid)
  end
  def cache_dir
"#{Rails.root}/tmp/uploads"
end
end

我设法修复了此问题。我不确定自己做了什么,但是有几个问题。(1)我认为我正在遇到验证错误,因为我在上传器中指定了一个文件夹。现在,我将Uploader中的目录设置为"并通过FOG配置指定文件夹。

(2)我遇到的另一个错误是时间不匹配。我在虚拟机中运行薄荷以进行开发,时间与现实不同。亚马逊对此提出了错误。一旦我设置了正确的时间,那就消失了。

最新更新