我正在尝试从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--
请帮我。
最佳答案
我认为这是因为第二个边界之后(就在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--