如前所述,我正在尝试将文件上传到 s3
require 'digest/md5'
require 'base64'
require 'aws-sdk'
def digest f
f.rewind
Digest::MD5.new.tab do |dig|
f.each_chunk{|ch| dig << ch}
end.base64digest
ensure
f.rewind
end
file = File.new(compress file) #file zipped with zip/zip
total = file.size
digest = digest(file)
s3 = AWS::S3::new(:access_key_id => @access_key_id, :secret_access_key
=> @secret_access_key)
bucket = s3.buckets['mybucket']
bucket.objects["myfile"].write :content_md5 => digest, :content_length
=> total do |buf,len|
buf.write(file.read len)
end
但我不断得到 AWS::S3::Errors::BadDigest 异常
如果我尝试在不通过 :content_md5 的情况下上传文件,一切顺利,存档下载并正确打开。
也正如我刚刚发现这在 ruby 1.9.3 上失败但在 1.9.2 上运行良好