2012-10-24 53 views
0

我想獲得carrierwave與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 

回答

0

我設法解決這個問題。我不完全確定我做了什麼,但有幾個問題。 (1)我想我得到了auth錯誤,因爲我在我的上傳器中指定了一個文件夾。現在,我將上傳器中的目錄設置爲「」並通過霧配置指定文件夾。

(2)我得到的另一個錯誤是時間不匹配。我在虛擬機器上運行薄荷來開發,時間與現實不同。亞馬遜在這方面拋出了一個錯誤。一旦我設定了正確的時間,那就消失了。