kylejginavan / youtube_it

An object-oriented Ruby wrapper for the YouTube GData API
http://groups.google.com/group/ruby-youtube-library
595 stars 223 forks source link

UploadError: Missing end boundary in multipart body. #167

Closed scaryguy closed 11 years ago

scaryguy commented 11 years ago

When I use standart upload method just the same as it exists in READ ME, I get this error:

client = YouTubeIt::Client.new(:username=>"USERNAME", :password=>"PASSWORD", :dev_key=>"DEV_KEY")
client.video_upload(File.open("/Users/scaryguy/sts_videos/youtube.mp4"), :title => "dfddftest",:description => "some description fdfdfdfd", :category => "People", :keywords => %w[cool blah test])
UploadError: Missing end boundary in multipart body.
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/bundler/gems/youtube_it-eb5058bd9379/lib/youtube_it/middleware/faraday_youtubeit.rb:27:in `on_complete'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/faraday-0.8.7/lib/faraday/response.rb:9:in `block in call'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/faraday-0.8.7/lib/faraday/response.rb:63:in `on_complete'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/faraday-0.8.7/lib/faraday/response.rb:8:in `call'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/bundler/gems/youtube_it-eb5058bd9379/lib/youtube_it/middleware/faraday_authheader.rb:17:in `call'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/faraday-0.8.7/lib/faraday/connection.rb:247:in `run_request'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/faraday-0.8.7/lib/faraday/connection.rb:112:in `post'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/bundler/gems/youtube_it-eb5058bd9379/lib/youtube_it/request/video_upload.rb:92:in `upload'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/bundler/gems/youtube_it-eb5058bd9379/lib/youtube_it/client.rb:117:in `video_upload'
    from (irb):4
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
    from /Users/scaryguy/.rvm/gems/ruby-2.0.0-p0@sts/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
$ rails -v
Rails 3.2.13

P.S: I had told you, chebyte, that my boss would make a small donation last day. I'm sorry but I can't force my boss to make a donation for something which we can not even use. I couldn't use the gem since I met it.

kylejginavan commented 11 years ago

Sorry you are unable to use this gem. At this point it is probably best you use a different youtube gem @scaryguy. Since I'm unable to reproduce this I'm closing this issue. Please provide a failing test or a patch for us to look at.

americos commented 11 years ago

Hi @kylejginavan,

I just experience the same error as @scaryguy, same kind of simple test based on the readme file. Here is the code I'm running (I removed user,pass,key, etc) : https://gist.github.com/americos/5709494

Using Ruby: 1.9.3p327

I would really appreciate if you can have a quick look, I don't know what I'm missing or doing wrong.

facetoe commented 11 years ago

I also encountered this error. Using: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]

I was attempting to upload a .avi file using the code in the readme.

facetoe commented 11 years ago

Just tried with a .mov file and also got the error. It's strange because last night it worked fine...

chrosciu commented 11 years ago

I investigated the issue. In my opinion problem is in the fact, that Faraday::Excon adapter tries to read body without passing buffer size (probably it assumes that body will be returned as a whole)

# TODO: support streaming requests
def read_body(env)
  env[:body].respond_to?(:read) ? env[:body].read : env[:body]
end

This goes to GreedyChainIO which assumes that default buffer size is 500k

class YouTubeIt::GreedyChainIO < DelegateClass(YouTubeIt::ChainIO)
  BIG_CHUNK = 512 * 1024 # 500 kb

  def read(any_buffer_size = nil)
    __getobj__.read(BIG_CHUNK)
  end

so it does not return more than 500k as a body to faraday (and body is cut in the half).

I made some tests - I tried to upload 600k video file to youtube and got topic error. Then I increased buffer size in GreedyChainIO to 1MB and upload was performed without any problems

However I have no idea how to fix this....

kylejginavan commented 11 years ago

@chrosciu well said and thank you. I will research this a bit more.

chrosciu commented 11 years ago

@kylejginavan: I prepared some fix both for this issue and #159.

https://github.com/neubloc/youtube_it/commit/715a4dcd6dd0c4b99f58116cf00aacf19171cc9c

If you think it is ok, I can prepare pull request

facetoe commented 11 years ago

Thanks @kylejginavan, I'll give it a test right away!

facetoe commented 11 years ago

I just tested the fix @kylejginavan and it worked perfectly!

chrosciu commented 11 years ago

@facetoe : glad to hear it :)

chebyte commented 11 years ago

@chrosciu thanks! I going to put your fix!

chebyte commented 11 years ago

@all today we going to make the new realease with the fix!