Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

New Contributor
Posts: 9
Registered: ‎01-13-2011
My Device: 9800

Problem uploading videos to youtube.com from my bb application.......

hi all,


         I have a problem uploading videos to youtube.com from my application.

This is the   link  of my previous thread, and this is my new thread. 


 I got some progress in youtube uploading. Below is the code I used.
         I sent the first request to get the auth token by sending the request to the below link using post method, using this documentation   <  ClientLogin auth token >                  
I used ClientLogin to the Auth Token . 
                < https://www.google.com/accounts/ClientLogin >
  After that I got the below response, 



hc = (HttpConnection)condesc.getConnection();
String req = "Email="+userName+"&Passwd="+passWord+"&service=youtube&source=mobileapp";
dos = hc.openDataOutputStream();
final int iResponseCode = hc.getResponseCode();
}catch(IOException ie)
This is the sample request format to send to the youtube.com.

a) This is a REST service transporting XML content.

b) It is an HTTP POST

c) You need to add a number of request headers to this post, including:

X-GData-Key - which has your developer key

Slug - which has your file name

The HTTPConnection provides you a way to add request headers

c) The XML content describes the video you are about to send.

d) The default data format for operations is the Atom XML standard

POST /resumable/feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: AuthSub token="DXAA...sdb8"
GData-Version: 2
X-GData-Key: key=adf15ee97731bca89da876c...a8dc
Content-Length: 1941255
Slug: my_file.mp4
Content-Type: application/atom+xml; charset=UTF-8

<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
    <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>


 After that I sent the request to the below link using Auth Token and Developer key,
< the got auth token in the above request................>
public void sendingMetadata()
String developerkey = "AI39si6kUPfbGVq6O8AYG_LBy3V7uIYGtjwFVwNHMXCRwjS0oGKqO_7qNc_UUZ4sl6Lrr5xAfRT9FIISYKQ3uWJk0ytKRlbDWg";
String authtoken " < my  auth token...........>";
String xmlData = "<?xml version=\"1.0\"?>";
xmlData += "<entry xmlns=\"http://www.w3.org/2005/Atom\"";
xmlData +="xmlns:media=\"http://search.yahoo.com/mrss/\"";
xmlData +="xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">";
xmlData +="<media:group>";
xmlData +="<media:title type=\"plain\">video1</media:title>";
xmlData +="<media:description type=\"plain\">";
xmlData +="my first video uploading......";
xmlData +="</media:description>";
xmlData +="<media:category";
xmlData += "</media:category>";
xmlData +="<media:keywords>toast, wedding</media:keywords>";
xmlData +="</media:group>";
xmlData +="</entry>";
int lentgh =  xmlData.getBytes().length;
String dataLength = new Integer(lentgh).toString();
hc = (HttpConnection)condesc.getConnection();
hc.setRequestProperty("Host", "uploads.gdata.youtube.com");
hc.setRequestProperty("Authorization","GoogleLogin auth="+authtoken);
hc.setRequestProperty("GData-Version", "2");
hc.setRequestProperty("Content-Length", "0");
                        //hc.setRequestProperty("Content-Length", dataLength);
hc.setRequestProperty("Slug", "sample.mp4");
                         //hc.setRequestProperty("Content-Type", "application/atom+xml; charset=UTF-8");
// String req = xmlData;
// dos = hc.openDataOutputStream();
// dos.write(req.getBytes());
final int iResponseCode = hc.getResponseCode();
Dialog.alert("Response.. code: "+Integer.toString(iResponseCode));
DataInputStream dis = hc.openDataInputStream();
StringBuffer buffer= new StringBuffer();
int chars;
while((chars = dis.read()) != -1)
buffer.append((char) chars);
}catch(Exception e)
       I tried sending meta data using the above code and I tried sending only headers without meta data while commenting some code as depicted in the above code. Now the problem ( while sending with and without metadata ), I getting an error with response code: 411, 
which means length required. 

              What should I do now, Is there any thing I'm missing in the above code snippets I sent. I'm doing this application for Blackberry (6.0 version), using Java Eclipse plug in for BlackBerry version 1.3.
             please help me to get ride of this situation, and its important for me in my project. 
             any help in this regard would be highly appreciated. 


New Contributor
Posts: 9
Registered: ‎01-13-2011
My Device: 9800

Re: Problem uploading videos to youtube.com from my bb application.......

please somebody help me........

New Contributor
Posts: 5
Registered: ‎02-08-2011
My Device: Not Specified

Re: Problem uploading videos to youtube.com from my bb application.......



It is normal because you dont put the length of the data that you have to send.


you have to choice:


1 - you comment this hc.setRequestProperty("Content-Length", "0"); and uncomment this 

                        //hc.setRequestProperty("Content-Length", dataLength);




2 - you can create a byte Array and inside you put the bytes of the data you want to send. look this example: 


byte[] postDataBytes = dataToSend.getBytes();


        hc.setRequestProperty("Content-Length",(new Integer(postDataBytes.length)).toString());


I hope my answer were helpfull.