如何在S3上载与CarrierWave在Ruby on Rails的应用sync_clock选项 [英] how to apply sync_clock option on S3 upload with CarrierWave in Ruby On Rails
问题描述
我得到这个错误每次因请求时间和当前时间太大的区别。我发现,我们需要申请sync_clock选项,但不能配置place.see我的配置请帮助我们配置同步时钟
错误:
预期(200)LT; =>实际(403禁止)
请求=&GT; {:头=&GT; {内容长度=&GT; 54911,内容类型=&gt;中为image / jpeg,X-AMZ-ACL=&gt;中公读,的cache控制=&gt;中最大年龄= 315576000,日期=&gt;中星期四,2013年10月24号1点14分14秒+0000,授权=&gt;中变,主机=&GT; 改变}:主机=&gt;中变,:模拟=&GT;无,:PATH =&gt;中/上传%2Fproject%2Fimage_1%2F697%2FHamburg - 斯派克-IM-BAU-090825.jpg:端口=&gt;中443:查询=&GT;无,:计划=&gt;中https开头, :body=>#<File:/app/tmp/carrierwave/20131024-0114-2-7499/Hamburg-Speicher-im-Bau-090825.jpg>, :预计=&GT; 200:幂=&GT;真,:方法=&gt;中PUT}
响应=&GT; #&LT; EXCON ::回应:0x0000000b72f0a0 @body =?&LT; XML版本= \1.0 \ encoding=\"UTF-8\"?>\n<Error><$c$c>RequestTimeTooSkewed</$c$c><Message>The请求时间和当前时间之间的差过large.</Message><MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds><RequestId>EA8E8FF76B54D7F3</RequestId><HostId>/RiS+pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL</HostId><RequestTime>Thu, 2013年10月24日一点14分14秒+ 0000 LT; / RequestTime&GT;&LT; ServerTime&GT; 2013-10-24T01:29:49Z&LT; / ServerTime&GT;&LT; /错误&gt;中,@headers = {X-AMZ-请求ID =&gt;中EA8E8FF76B54D7F3,X-AMZ-ID-2=&gt;中/ RIS + pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL,内容类型=&gt;中的应用/ xml的,传输编码=&gt;中分块,日期=&gt;中星期四,2013年10月24日1时29分47秒格林尼治标准时间,连线=&gt;中关闭,服务器=&gt;中AmazonS3},@状态= 403&GT;
供应商/包/红宝石/ 1.9.1 /宝石/ EXCON-0.6.6 / lib中/ EXCON / connection.rb:190:在'请求'
初始
CarrierWave.configure办|配置|
如果Rails.env.production?
config.fog_directory ='ESE-PROD
config.fog_host ='https://s3.amazonaws.com/ese-prod
其他
config.fog_directory ='ESE-dev的'
config.fog_host ='https://s3.amazonaws.com/ese-dev
结束
如果Rails.env.production? || Rails.env.development?
config.fog_credentials = {
:供应商=&GT; AWS,
:aws_access_key_id =&GT; AAAAAAAAAAA,
:aws_secret_access_key =&GT; BBBBBBBBBBBB,
:地区=&GT; 我们东-1'
}
config.fog_public =真
config.fog_attributes = {'的Cache-Control'=&GT; 最大年龄= 315576000'}
config.root = Rails.root.join(TMP)#加入这些...
config.cache_dir ='carrierwave'#...两行
#ELSIF Rails.env.development?
#config.storage =:文件
其他
config.storage =:文件
结束
结束
uploder
类ImageUploader&LT; CarrierWave ::上传::基地
包括CarrierWave :: MiniMagick
如果Rails.env.production? || Rails.env.development?
存储:雾
其他
存储:文件
结束
高清store_dir
上传/#{model.class.to_s.underscore} / {#} mounted_as /#{model.id}
结束
版本:拇指做
过程:resize_to_limit =&GT; [50,50]
结束
版本:合作伙伴做
过程:resize_to_limit =&GT; [150,150]
结束
高清extension_white_list
%W(JPG JPEG GIF PNG)
结束
结束
这是不幸的是,这种情况发生的事情。值得庆幸的是有一个修复程序。
在初始化,你应该能够做这样的事情:
雾:: Storage.new(fog_credentials).sync_clock
您应该能够使用要传递到配置在初始化程序fog_credentials此相同的价值观。 sync_clock做一个简单的请求至S3和存储偏移量(和随后修改时间戳发送由偏移)。所以,应该确保你不会看到这个错误的话(尽管它不应该拿出那个时候,也就是说,如果你重新部署到Heroku上,新dynos也许就不会歪斜仍然)。希望清除它,但如果需要,竭诚为更多的。
I got This error Every time due to difference between the request time and the current time is too large. I found that we need to apply sync_clock option but not able to configuration place.see my configuration please help us to configure to sync clock
Error :
Expected(200) <=> Actual(403 Forbidden)
request => {:headers=>{"Content-Length"=>54911, "Content-Type"=>"image/jpeg", "x-amz-acl"=>"public-read", "Cache-Control"=>"max-age=315576000", "Date"=>"Thu, 24 Oct 2013 01:14:14 +0000", "Authorization"=>"changed", "Host"=>"changed"}, :host=>"changed", :mock=>nil, :path=>"/uploads%2Fproject%2Fimage_1%2F697%2FHamburg-Speicher-im-Bau-090825.jpg", :port=>"443", :query=>nil, :scheme=>"https", :body=>#<File:/app/tmp/carrierwave/20131024-0114-2-7499/Hamburg-Speicher-im-Bau-090825.jpg>, :expects=>200, :idempotent=>true, :method=>"PUT"}
response => #<Excon::Response:0x0000000b72f0a0 @body="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error><Code>RequestTimeTooSkewed</Code><Message>The difference between the request time and the current time is too large.</Message><MaxAllowedSkewMilliseconds>900000</MaxAllowedSkewMilliseconds><RequestId>EA8E8FF76B54D7F3</RequestId><HostId>/RiS+pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL</HostId><RequestTime>Thu, 24 Oct 2013 01:14:14 +0000</RequestTime><ServerTime>2013-10-24T01:29:49Z</ServerTime></Error>", @headers={"x-amz-request-id"=>"EA8E8FF76B54D7F3", "x-amz-id-2"=>"/RiS+pn3JcKzOoArMhFRYmSBRYwRAptugp8W32XAT4vupukmxMCtHRKIHy7wy9BL", "Content-Type"=>"application/xml", "Transfer-Encoding"=>"chunked", "Date"=>"Thu, 24 Oct 2013 01:29:47 GMT", "Connection"=>"close", "Server"=>"AmazonS3"}, @status=403>
vendor/bundle/ruby/1.9.1/gems/excon-0.6.6/lib/excon/connection.rb:190:in `request'
initializer
CarrierWave.configure do |config|
if Rails.env.production?
config.fog_directory = 'ese-prod'
config.fog_host = 'https://s3.amazonaws.com/ese-prod'
else
config.fog_directory = 'ese-dev'
config.fog_host = 'https://s3.amazonaws.com/ese-dev'
end
if Rails.env.production? || Rails.env.development?
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => 'AAAAAAAAAAA',
:aws_secret_access_key => 'BBBBBBBBBBBB',
:region => 'us-east-1'
}
config.fog_public = true
config.fog_attributes = {'Cache-Control' => 'max-age=315576000'}
config.root = Rails.root.join('tmp') # adding these...
config.cache_dir = 'carrierwave' # ...two lines
# elsif Rails.env.development?
# config.storage = :file
else
config.storage = :file
end
end
uploder
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
if Rails.env.production? || Rails.env.development?
storage :fog
else
storage :file
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_limit => [50, 50]
end
version :partner do
process :resize_to_limit => [150, 150]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
This is, unfortunately, a thing that happens. Thankfully there is a fix.
In the initializer you should be able to do something like this:
Fog::Storage.new(fog_credentials).sync_clock
You should be able to use the same values that you are passing to config in your initializer for fog_credentials here. sync_clock makes a simple request to S3 and stores the offset (and then modifies timestamps it sends by the offset). So that should ensure you won't see this error any more (though it shouldn't come up that often, ie if you redeploy to heroku, the new dynos probably would not have the skew still). Hope that clears it up, but happy to help more if needed.
这篇关于如何在S3上载与CarrierWave在Ruby on Rails的应用sync_clock选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!