2012-10-30 5 views
3

나는 다음과 같은 간단한 코드로 S3에 파일을 업로드하려고 : 서버에 대한 귀하의 소켓 연결이 루비 AWS-SDK - 시간 제한 오류

하지 않았다 :

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

나는 다음과 같은 얻을 타임 아웃 기간 내에 읽거나 쓰게됩니다. 유휴 연결이 닫힙니다.

무엇이 잘못 될 수 있습니까? 어떤 조언을 부탁드립니다.

답변

7

이 시간 제한은 일반적으로 컨텐츠 길이가 올바르게 열린 파일을 기반으로 판단 할 수 없을 때 발생합니다. S3는 앞으로 오지 않을 추가 바이트를 기다리고 있습니다. 수정 프로그램은 매우 간단합니다. 바이너리 모드로 파일을여십시오.

루비 1.9

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

루비 1.8

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

당신이 파일에 경로에 통과하면 당신을 위해 이것을 처리 할 AWS-SDK 보석 :

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

희망이 도움이됩니다.

+1

2.0에 대한 루비 1.9의 수정 사항이 동일합니까? 2.0에서 타임 아웃 오류 문제가 발생했습니다. 1.9.3에서는'open (file)'만으로도 잘 작동했다. 동일한 문제가 여기에 언급 된 https://github.com/aws/aws-sdk-ruby/issues/241 –

1

시간 초과 매개 변수를 수정하고 문제가 지속되는지 확인하십시오. 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)