1

I am trying to upload a video to YouTube from my Android application, using YouTube API v2.0 – Resumable Uploads.

Using that I have completed two steps successfully, but in the third step, where I have to upload the actual video to the url location I got from the step 2, I am getting an error message:

Content-Type application/x-www-form-urlencoded is not a valid input type.

I am sending the put request using the following protocol:

PUT <upload_url> HTTP/1.1
Host: uploads.gdata.youtube.com
Content-Type: <video_content_type>
Content-Length: <content_length>

<Binary_file_data> 

using this code:

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

I also tried to send a request using MultipartEntity but every time I am getting the same error Content-Type application/x-www-form-urlencoded is not a valid input type.

Gilles 'SO- stop being evil'
  • 104,111
  • 38
  • 209
  • 254
W00di
  • 954
  • 12
  • 21

0 Answers0