Youtube File upload issue

Discussion in 'Ruby' started by nico itkin, Sep 23, 2010.

  1. nico itkin

    nico itkin Guest

    Hello,

    I'm triying to upload video to google api via direct upload
    (http://code.google.com/intl/fr/apis/youtube/2.0/developers_guide_protocol.html#Direct_uploading).

    I'm using an rails active resource class and would lie to handle the
    video uploading in a custom method with Nett::HTTP

    Here is google requirement :

    POST /feeds/api/users/default/uploads HTTP/1.1
    Host: uploads.gdata.youtube.com
    Authorization: AuthSub token="DXAA...sdb8"
    GData-Version: 2
    X-GData-Key: key=adf15ee97731bca89da876c...a8dc
    Slug: video-test.mp4
    Content-Type: multipart/related; boundary="f93dcbA3"
    Content-Length: 1941255
    Connection: close

    --f93dcbA3
    Content-Type: application/atom+xml; charset=UTF-8

    <?xml version="1.0"?>
    <entry xmlns="http://www.w3.org/2005/Atom"
    xmlns:media="http://search.yahoo.com/mrss/"
    xmlns:yt="http://gdata.youtube.com/schemas/2007">
    <media:group>
    <media:title type="plain">Bad Wedding Toast</media:title>
    <media:description type="plain">
    I gave a bad toast at my friend's wedding.
    </media:description>
    <media:category
    scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People
    </media:category>
    <media:keywords>toast, wedding</media:keywords>
    </media:group>
    </entry>
    --f93dcbA3
    Content-Type: video/mp4
    Content-Transfer-Encoding: binary

    <Binary File Data>
    --f93dcbA3--



    Here is my request object before to be sent :
    (irb)> y request

    body: |
    --RubyMultipartClient901619ZZZZZ
    Content-Type: application/atom+xml; charset=UTF-8

    <?xml version="1.0"?>
    <entry xmlns:yt="http://gdata.youtube.com/schemas/2007"
    xmlns="http://www.w3.org/2005/Atom"
    xmlns:media="http://search.yahoo.com/mrss/">
    <media:group>
    <media:title type="plain">test 7</media:title>
    <media:description type="plain"></media:description>
    <media:category
    scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Film</media:category>
    <media:keywords></media:keywords>
    </media:group>
    </entry>
    --RubyMultipartClient901619ZZZZZ
    Content-Type: video/mp4
    Content-Transfer-Encoding: binary


    --RubyMultipartClient901619ZZZZZ--

    body_stream:
    header:
    slug:
    - 01.mp4
    x-gdata-key:
    -
    key=AI39si57I1WXXFZSHlDFjrfUgBapS7DoJ0hPppuqgC2FY_vK-nUQ8Iw7lTUJTdqwSCstyIhSWBk-C9JI1DCQolrmVvTcj6xvLg
    content-type:
    - multipart/related; boundary="RubyMultipartClient901619ZZZZZ"
    authorization:
    - AuthSub token="1/qqpJVDJ4Gziq6pLv8tmMWgIv4zxvwk3sZP9PiVHlCt4"
    gdata-version:
    - "2"
    content-length:
    - "672"
    method: POST
    path: /feeds/api/users/default/uploads
    request_has_body: true
    response_has_body: true

    I triyed to read the file and include its content in the body post, also
    tryed to include it after encoding in base64
    (Base64.encode64(file.read))

    The request is build and sent as follow :

    uri =
    URI.parse("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads")
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::post.new(uri.request_uri)
    request.initialize_http_header(headers)
    request.body = post_body
    response = http.request(request)


    But it keeps responding :

    #<Net::HTTPBadRequest 400 Bad Request readbody=true>

    I don't know what's wrong i'm completely stuck, could you give me a hand
    ?
    --
    Posted via http://www.ruby-forum.com/.
     
    nico itkin, Sep 23, 2010
    #1
    1. Advertising

  2. nico itkin

    nico itkin Guest

    I succeeded to make it work, by setting the post body as follow :

    data = %{--bbe873dc\r
    Content-Type: application/atom+xml; charset=UTF-8

    #{xml_entry}\r
    --bbe873dc\r
    Content-Type: #{meta[:file].content_type}
    Content-Transfer-Encoding: binary

    #{meta[:file].read}\r
    --bbe873dc--\r\n}

    I still don't understand why it wasn't working properly before ... :/
    --
    Posted via http://www.ruby-forum.com/.
     
    nico itkin, Sep 23, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. railsaware.com
    Replies:
    0
    Views:
    315
    railsaware.com
    Nov 6, 2006
  2. Terry Reedy

    YouTube written in Python

    Terry Reedy, Dec 13, 2006, in forum: Python
    Replies:
    12
    Views:
    453
    Terry Reedy
    Dec 14, 2006
  3. Leif K-Brooks

    YouTube showing repr() of a tuple

    Leif K-Brooks, Mar 29, 2007, in forum: Python
    Replies:
    5
    Views:
    284
    Leif K-Brooks
    Apr 2, 2007
  4. David Cox

    youtube soundclick clapometer?

    David Cox, May 21, 2007, in forum: Java
    Replies:
    0
    Views:
    315
    David Cox
    May 21, 2007
  5. 2Barter.net
    Replies:
    1
    Views:
    279
    Twisted
    Jul 6, 2007
Loading...

Share This Page