Ruby aws-sdk - timeout error
amazon-s3, ruby, ruby-on-rails, ruby-on-rails-3
Solution
This timeout is generally happens when the content length could not be correctly determined based on the opened file. S3 is waiting for additional bytes that aren't coming. The fix is pretty simple, just open your file in binary mode.
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'))
The aws-sdk gem will handle this for you if you pass in the the path to the file:
# 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)
Also, you can write to an object in s3 before it exists, so you could also do:
# my favorite syntax
obj = s3.buckets['bucket-name'].objects['object-key'].write(:file => path_to_file)
Hope this helps.
Problem
I am trying to upload a file to S3 with the following simple code: ``` bucket.objects.create("sitemaps/event/#{file_name}", open(file)) ``` I get the following: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. What could be going wrong? Any tips will be appreciated.