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

Posts: 38
Registered: ‎04-11-2012
My Device: 8520
My Carrier: RIM

Problem when uploading image

Hi Sir ,
I have some problem when uploading image on twitter .
i am able to update status successfully but when uploading image it give error "Bad Authentication data".
i am trying like this

public static void postImage(Token token) {
Hashtable params = new Hashtable();
params.put("status", "Hello How r u?");
try {
InputStream ios = Utilities.class.getResourceAsStream("/videotalkies_68.png");
byte[] fileBytes = getUrlEncodeData(IOUtilities.streamToBytes(ios));

Credential credential = new Credential(Constant.CONSUMER_KEY, Constant.CONSUMER_SECRET, token);
UserAccountManager m = UserAccountManager.getInstance(credential);
if (m.verifyCredential()) {
XAuthSigner oAuthSigner = new XAuthSigner(Constant.CONSUMER_KEY, Constant.CONSUMER_SECRET);
Hashtable headers =getHeaderssignForAccessToken(credential.getUsernameOrEmail(), credential.getString(MetadataSet.CREDENTIAL_PASSWORD));
byte[] bs = new HttpMultipartRequest("https://api.twitter.com/1.1/statuses/update_with_media.json", params, "media[]", "videotalkies_68.png", "application/octet-stream", fileBytes, headers).send();
System.out.println("Utilities.postImage()==out====\n" + new String(bs));
} catch (Exception e) {
System.out.println("Utilities.postImage()Error=========" + e.getMessage() + '\t' + e.getClass().getName());

private static byte[] getUrlEncodeData(byte[] streamToBytes) {
String data = URLUTF8Encoder.encode(new String(streamToBytes));
return data.getBytes();

public Hashtable getHeaderssignForAccessToken(String username, String password) {
Hashtable headers = new Hashtable();

headers.put(OAuthConstants.MODE, "client_auth");
headers.put(OAuthConstants.USERNAME, username);
headers.put(OAuthConstants.PASSWORD, password);
OAuthParameters params = new OAuthParameters(consumerKey);
// String str = getSignatureBaseString(req, params);
String str = getSignature("", consumerSecret, OAuthConstants.EMPTY_TOKEN_SECRET);
params.put(OAuthConstants.SIGNATURE, str);
str = params.getAuthorizationHeaderValue();
headers.put(OAuthConstants.HEADER, str);
return headers;

Can someone Help me?