我正在尝试使用YouTube API v2.0 - Resumable Uploads从我的Android应用上传视频到YouTube。
使用它我已成功完成两个步骤,但在第三步中,我必须将实际视频上传到我从步骤2获得的URL位置,我收到一条错误消息:
Content-Type application / x-www-form-urlencoded不是有效的输入类型。
我使用以下协议发送put请求:
PUT <upload_url> HTTP/1.1
Host: uploads.gdata.youtube.com
Content-Type: <video_content_type>
Content-Length: <content_length>
<Binary_file_data>
使用此代码:
HttpPut put=new HttpPut(location);
InputStream is = new FileInputStream(video_file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] b = new byte[(int) length];
int bytesRead;
while ((bytesRead = is.read(b)) != -1) {
bos.write(b, 0, bytesRead);
}
byte[] bytes = bos.toByteArray();
// ContentType type=
ByteArrayEntity byte_entity=new ByteArrayEntity(bytes);
byte_entity.setContentType("video/3gpp");
put.setEntity(byte_entity);
HttpResponse upload_response = client.execute(put);
我还尝试使用MultipartEntity发送请求,但每次收到同样的错误Content-Type application/x-www-form-urlencoded is not a valid input type.