Youtube File upload issue


I'm triying to upload video to google api via direct upload

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
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

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

<?xml version="1.0"?>
<entry xmlns=""
    <media:title type="plain">Bad Wedding Toast</media:title>
    <media:description type="plain">
      I gave a bad toast at my friend's wedding.
    <media:keywords>toast, wedding</media:keywords>
Content-Type: video/mp4
Content-Transfer-Encoding: binary

<Binary File Data>

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

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

  <?xml version="1.0"?>
  <entry xmlns:yt=""
      <media:title type="plain">test 7</media:title>
      <media:description type="plain"></media:description>
  Content-Type: video/mp4
  Content-Transfer-Encoding: binary


  - 01.mp4


  - multipart/related; boundary="RubyMultipartClient901619ZZZZZ"
  - AuthSub token="1/qqpJVDJ4Gziq6pLv8tmMWgIv4zxvwk3sZP9PiVHlCt4"
  - "2"
  - "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

The request is build and sent as follow :

uri =
http =, uri.port)
request =
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

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

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

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


I still don't understand why it wasn't working properly before ... :confused:


Posted via