s3
s3 copied to clipboard
S3::Error::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
Hi.
I'm trying to upload an image to my bucket. Thats my code:
require 's3'
service = S3::Service.new(access_key_id: 'xxxxx', secret_access_key: 'xxxxx')
service.buckets # returns me correct list of my buckets so connection is established and works ok
obj = service.buckets.first.objects.build('1.jpg') # now create an object
obj.content = open('1.jpg', 'rb', encoding: 'BINARY') # file i want to upload
obj.save # save it
result is:
/usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:217:in `handle_response': Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. (S3::Error::RequestTimeout)
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:204:in `send_request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:201:in `send_request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/connection.rb:89:in `request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/service.rb:74:in `service_request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/bucket.rb:171:in `bucket_request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:207:in `object_request'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:189:in `put_object'
from /usr/lib/ruby/gems/1.9.1/gems/s3-0.3.11/lib/s3/object.rb:83:in `save'
from test.rb:8:in `'
I'm following your guide and and everything except upload works :( My ruby version is 1.9.3 btw.
I'm sorry for the delay. I'm quite busy recently, so I'm afraid you need to debug the code on your own. You can also consider switching to a different S3 library.
Hi, I had the same problem I will try to debug it but for me solution was:
File.open("file.png", :encoding => "BINARY")
Binary is the key. If I will find out solution You could find it in my fork.
edit
Is really weird because right now it works even without binary attribute. Something strange going on.
Thanks for reporting, please create a pull request when you fix the problem.
For anyone trying to figure this out, use File.read instead of File.open or open
@abunsenonesale Do you know how to reproduce this error? Could you also provide explanation for that why read is better then open in this case?
I could not reproduce that error so I do not know if it was related with some specific ruby version or some other black magic. If you could provide some details it will be cool to understand what happened and to fix that.
I have this now, although it was working when I initially implemented it, it now doesn't!
require "s3"
service = S3::Service.new(
:access_key_id => ENV['ACCESS_KEY_ID'],
:secret_access_key => ENV['SECRET_ACCESS_KEY']
)
bucket_name = ENV['BUCKET_NAME']
file = ENV['FILENAME']
bucket = service.buckets.find(bucket_name)
object = bucket.objects.build(file)
object.content = open(file)
object.save
Result
S3::Error::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
from /Users/ian/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/s3-0.3.23/lib/s3/connection.rb:216:in `handle_response'
Using : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
[13] pry(main)> object.content = File.open("/Users/ian/Desktop/test.png")
=> #<File:/Users/ian/Desktop/test.png>
Reading over here https://github.com/aws/aws-sdk-js/issues/281 it seems it's an issue with the content-length.