Tumblr photo upload issue

250 views
Skip to first unread message

Akmal Javid

unread,
May 1, 2013, 3:47:51 AM5/1/13
to tumbl...@googlegroups.com
Hi 
I want to upload an image by using Tumblr Image Upload API but i have receive response from server like this.{"meta":{"status":400,"msg":"Bad Request"},"response":{"errors":["Error uploading photo."]}}.
My code is as under. 
private void uploadToTumblr(Bitmap photo)
{
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(Constants.TUMB_CONSUMER_KEY, Constants.TUMB_CONSUMER_SECRET);
String token=pref.getString(Constants.TUM_TOKEN, "");
String tokenSecret=pref.getString(Constants.TUM_TOKEN_SECRET, "");
consumer.setTokenWithSecret(token,tokenSecret);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] bytes = stream.toByteArray();
String text ="SNAP";
HttpContext context = new BasicHttpContext();
HttpPost request = new HttpPost("http://api.tumblr.com/v2/blog/abcd.tumblr.com/post");
String data = null;
/********************I have tried to send this type of data**********************/
//data=toBinary(bytes);
//data = Base64.encodeToString(bytes, false);
//data = new String(bytes, "UTF-8");
//data=URLEncoder.encode(new String(bytes));
//data=new String(stream.toByteArray());
data=Base64.encodeToString(bytes, Base64.URL_SAFE);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4); 
try {
nameValuePairs.add(new BasicNameValuePair("type", "photo"));
nameValuePairs.add(new BasicNameValuePair("caption",text)); 
nameValuePairs.add(new BasicNameValuePair("data", data));
request.setEntity(new UrlEncodedFormEntity(nameValuePairs));
consumer.sign(request);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request, context);
HttpEntity responseEntity = response.getEntity(); 
if (responseEntity != null) 

String responce=EntityUtils.toString(responseEntity);
System.out.println("Responce = "+responce);
}
}catch (Exception e2){} 
}

John Crepezzi

unread,
May 1, 2013, 10:28:40 AM5/1/13
to tumbl...@googlegroups.com
Hey Akmal,
You should take a look at Jumblr, our official Java client:



--
You received this message because you are subscribed to the Google Groups "Tumblr API Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tumblr-api+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages