Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading a video to youtube using youtube Data API: Broken pipe (Errno::EPIPE)

I'm trying to upload a local video file to my youtube account using youtube data api.

Example: https://github.com/youtube/api-samples/blob/master/ruby/upload_video.rb

Call:

$ ruby upload_video.rb --file video.mp4 

I'm getting an error message:

/Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `syswrite': Broken pipe (Errno::EPIPE)
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:326:in `do_write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/openssl/buffering.rb:344:in `write'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `copy_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:202:in `send_request_with_body_stream'
from /Users/user/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/net/http/generic_request.rb:132:in `exec'
...
from upload_video.rb:73:in `main'
from upload_video.rb:91:in `<main>'

upload_video.rb (line 73):

videos_insert_response = client.execute!(
  :api_method => youtube.videos.insert,
  :body_object => body,
  :media => Google::APIClient::UploadIO.new(opts[:file], 'video/*'),
  :parameters => {
    :uploadType => 'resumable',
    :part => body.keys.join(',')
  }
)
like image 265
BearGrylls Avatar asked Dec 25 '22 08:12

BearGrylls


1 Answers

google-api-client uses faraday gem which default http adapter is Net::HTTP. And it seems it's not working properly. So we need to switch it to something else. I changed it to httpclient and now it works fine. Just add this line somewhere in the beginning of your whatever.rb file (right after requiring google's libs):

Faraday.default_adapter = :httpclient

Full list of supported http adapters could be found here: https://github.com/lostisland/faraday#faraday

like image 195
BearGrylls Avatar answered Dec 28 '22 05:12

BearGrylls