3

次の簡単なコードでファイルをS3にアップロードしようとしています。

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

私は次のようになります:

サーバーへのソケット接続は、タイムアウト期間内に読み取りまたは書き込みが行われませんでした。アイドル接続は閉じられます。

何がうまくいかない可能性がありますか?ヒントをいただければ幸いです。

4

2 に答える 2

7

このタイムアウトは通常、開いているファイルに基づいてコンテンツの長さを正しく決定できなかった場合に発生します。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-sdkgemがこれを処理します。

# 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)

お役に立てれば。

于 2012-10-31T18:40:59.437 に答える
1

タイムアウトパラメータを変更して、問題が解決するかどうかを確認してください。

AWS Webサイトから: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)
于 2012-10-30T23:58:04.200 に答える