Error code 214 while uploading video



Am trying to upload video using Java on twitter and it keeps failing for same reason {“errors”:[{“code”:214,“message”:“Bad request.”}]}.

Twitter says the video needs to base64-encoded chunk of media file. My code below for uploading the same

String url = ""+mediaId+"&segment_index=0";
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(this.consumerKey, this.consumerSecret); 
HttpPost request = new HttpPost(url);
request.setHeader("content-type", "multipart/form-data");
MultipartEntity multiPartEntity = new MultipartEntity () ;
multiPartEntity.addPart("command", new StringBody("APPEND")) ;
multiPartEntity.addPart("media_id", new StringBody(mediaId)) ;
//FileBody fileBody = new FileBody(file) ;
byte[] file64 = loadFileAsBytesArray(file);
ContentBody cd = new InputStreamBody(new ByteArrayInputStream(file64), file.getName());
multiPartEntity.addPart("media_data",  cd);
multiPartEntity.addPart("media_data", cd) ;
multiPartEntity.addPart("segment_index", new StringBody("0") ) ;
DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpResponse response = httpClient.execute(request);
int code = response.getStatusLine().getStatusCode();
System.err.println("Code "+code);
 public static byte[] loadFileAsBytesArray(File file) throws Exception 
    int length = (int) file.length();
    BufferedInputStream reader = new BufferedInputStream(new FileInputStream(file));
    byte[] bytes = new byte[length];, 0, length);
    return bytes;

I am able to get the media id, so am sure the authorization if fine. Am I missing something in uploading the base 64 file?


Hello @rohitgu,

I am trying to achieve the same behaviour to upload video to twitter…could you please share he code that you are using to uploa the video and also please let me know how you are handling authorisation here…