格式错误的多部分身体YouTube视频上传

时间:2012-09-17 12:02:34

标签: iphone objective-c ios youtube-api gdata

我正在尝试从iPhone应用上传视频到youtube。但我得到“格式错误的多部分身体”。

这是我的请求格式: -

标题:

Authorization: Bearer ya29.AHES6ZRfVWRgOe78g4eHz8v85yFztU-ea3jEy6d_4mbEkAMVD33_1w
GData-Version: 2
Host: uploads.gdata.youtube.com
X-GData-Key: key=AI39si5TXQBExBk3eT3cn4eCOSKr1GEOJd5_HJ-RjUGPErby1Qn4aOL-HlecdrxZ3Ur7QocO8Di9wHxUdV2fSYTM3mtFCyzl_A
Slug: summer_vacation.mp4
Content-Type: multipart/related; boundary="f93dcbA3"

请求正文:

--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>
    <yt:incomplete/>
    <media:category
      scheme="http://gdata.youtube.com/schemas/2007/categories.cat">Travel
    </media:category>
  </media:group>
</entry>
--f93dcbA3

Content-Type: video/mp4
Content-Transfer-Encoding: binary

--f93dcbA3--

请帮帮我。

1 个答案:

答案 0 :(得分:0)

我认为这是因为你的第二个边界之后的额外行(就在Content-Type: video/mp4标题之前)。另外,请务必在Content-Transfer-Encoding: binary标题和二进制数据之间添加一行。

Google Example为模型:

POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
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--