0

我正在尝试让carrierwave 与S3 一起工作,但我收到了一个签名不匹配错误。奇怪的是,carrierwave 似乎没有发送正确的密钥。在错误中,帖子给出为:

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

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

雾.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

上传者.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
4

1 回答 1

0

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

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

于 2012-10-25T17:40:16.510 回答