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(',')
}
)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With