rails carrierwave / s3签名不匹配。错误的私钥

时间:2012-10-24 12:53:53

标签: ruby-on-rails-3 amazon-s3 carrierwave

我正在尝试使用S3运行载波,我收到的签名与错误不符。奇怪的是,它看起来不像载波正在发送正确的密钥。在错误中,帖子的名称为:

"Authorization"=>"AWS AKIAIOLWQKSJFH6E3I5Q:vKgyAw2z4c8zzqGWoxLUbw7I5oI="

我认为应该是我的公钥:privatekey。问题是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 个答案:

答案 0 :(得分:0)

我设法解决了这个问题。我不确定我做了什么,但有几个问题。 (1)我认为我收到了auth错误,因为我在上传器中指定了一个文件夹。现在,我将上传器中的目录设置为“”并通过雾配置指定文件夹。

(2)我得到的另一个错误是时间不匹配。我在虚拟机中运行模具进行开发,时间与现实不同。亚马逊在那引发了一个错误。一旦我设定了正确的时间,那就消失了。