繁体   English   中英

Ruby aws-sdk - 超时错误

[英]Ruby aws-sdk - timeout error

我正在尝试使用以下简单代码将文件上传到S3:

bucket.objects.create("sitemaps/event/#{file_name}", open(file))

我得到以下内容:

未在超时期限内读取或写入与服务器的套接字连接。 空闲连接将被关闭。

怎么可能出错? 任何提示将不胜感激。

当基于打开的文件无法正确确定内容长度时,通常会发生此超时。 S3正在等待未来的其他字节。 修复非常简单,只需以二进制模式打开文件即可。

Ruby 1.9

bucket.objects.create("sitemaps/event/#{file_name}", open(file, 'rb', :encoding => 'BINARY'))

Ruby 1.8

bucket.objects.create("sitemaps/event/#{file_name}", open(file, 'rb'))

如果您传入文件的路径,aws-sdk gem将为您处理:

# use a Pathname object
bucket.objects.create(key, Pathname.new(path_to_file))

# or just the path as a string
bucket.objects.create(key, :file => path_to_file)

此外,您可以在s3中存在之前写入对象,因此您还可以执行以下操作:

# my favorite syntax
obj = s3.buckets['bucket-name'].objects['object-key'].write(:file => path_to_file)

希望这可以帮助。

尝试修改超时参数并查看问题是否仍然存在。

从AWS网站: http//aws.amazon.com/releasenotes/5234916478554933 (新配置选项)

# the new configuration options are:
AWS.config.http_open_timeout #=> new session timeout (15 seconds)
AWS.config.http_read_timeout #=> read response timeout (60 seconds)
AWS.config.http_idle_timeout #=> persistant connections idle longer are closed (60     seconds)
AWS.config.http_wire_trace #=> When true, HTTP wire traces are logged (false)

# you can update the timeouts (with seconds)
AWS.config(:http_open_timeout => 5, :http_read_timeout => 120)

# log to the rails logger
AWS.config(:http_wire_trace => true, :logger => Rails.logger)

# send wire traces to standard out
AWS.config(:http_wire_trace => true, :logger => nil)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM