title: Ruby : File upload to Google drive using google-api-ruby-client SDK failing with Timeout::Error
body: <p>I am using the google-api-ruby-client in my Rails application to interact with Google Drive. All the basic functions like listing files in a folder, fetching, moving, copying and deleting a file, create new folder, etc are working fine.</p>
  
  <p>However uploading a new file is always failing with Timeout::Error</p>
  
  <p>I receive the file to be uploaded as a regular file upload from my website (multipart/form-data) and this is how I upload it to Google drive</p>
  
  <pre><code>result = nil
  new_file_obj = google_drive.files.insert.request_schema.new({
    'title' =&gt; file_name,
    'mimeType' =&gt; file_mime_type,
    'parents' =&gt; [{'id' =&gt; current_folder_id}]
  })
  
  file_content = Google::APIClient::UploadIO.new(new_file.tempfile, file_mime_type, file_name)
  
  result = google_client.execute(
      api_method: google_drive.files.insert,
      body_object: new_file_obj,
      media: file_content,
      parameters: {
        'uploadType' =&gt; 'multipart',
        'alt' =&gt; 'json'
      }
    )
  </code></pre>
  
  <p>Here <code>new_file</code> is the file that was uploaded by the client. <code>new_file.tempfile</code> gives an object of type <code>Tempfile</code>.</p>
  
  <p>The <code>execute</code> method never returns and ultimately I get a Timeout::Error exception. This is the relevant stack trace : </p>
  
  <pre><code>/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill'
  /lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
  /lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
  /lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
  /lib/ruby/1.9.1/net/http.rb:2211:in `read_status_line'
  /lib/ruby/1.9.1/net/http.rb:2200:in `read_new'
  /lib/ruby/1.9.1/net/http.rb:1183:in `transport_request'
  /lib/ruby/1.9.1/net/http.rb:1169:in `request'
  /lib/ruby/1.9.1/net/http.rb:1162:in `block in request'
  /lib/ruby/1.9.1/net/http.rb:627:in `start'
  /lib/ruby/1.9.1/net/http.rb:1160:in `request'
  /lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:74:in `perform_request'
  /lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:37:in `call'
  /lib/ruby/gems/1.9.1/gems/faraday-0.8.4/lib/faraday/request/url_encoded.rb:14:in `call'
  /lib/ruby/gems/1.9.1/gems/google-api-client-0.5.0/lib/google/api_client/request.rb:154:in `send'
  /lib/ruby/gems/1.9.1/gems/google-api-client-0.5.0/lib/google/api_client.rb:546:in `execute'
  </code></pre>
  
  <p>I wrote this code following the example here : <a href="https://developers.google.com/drive/examples/ruby#saving_new_files" rel="nofollow">https://developers.google.com/drive/examples/ruby#saving_new_files</a> What am I missing here?</p>
  
  <p>The file I am trying to upload is a small png image. The file is coming properly to my web application, as I can view the file if I write it to disk. The Google servers are definitely not down, as I can upload a file from drive.google.com. This also means my network is good enough.</p>
  
  <p>So what exactly is causing the timeout?</p>
  
  <p>A solution to this same exception is mentioned as increasing the read_timeout (http://stackoverflow.com/questions/10011387/rescue-in-rbuf-fill-timeouterror-timeouterror). Is that what I should do? If so how do I do it here using the google-api-ruby-client sdk?</p>