Created
September 28, 2012 21:29
-
-
Save graingert/3802170 to your computer and use it in GitHub Desktop.
CakeCam.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static String imgurUpload(MBFImage image, String name, String type, String title, String caption) throws IOException{ | |
| // Creates Byte Array from picture | |
| ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
| ImageUtilities.write(image, type, baos); | |
| HttpPost post = new HttpPost("http://api.imgur.com/2/upload.json"); | |
| post.setHeader("Accept", "application/json"); | |
| List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); | |
| nameValuePairs.add(new BasicNameValuePair("image", Base64.encodeBase64String(baos.toByteArray()))); | |
| nameValuePairs.add(new BasicNameValuePair("name", name)); | |
| nameValuePairs.add(new BasicNameValuePair("type", type)); | |
| nameValuePairs.add(new BasicNameValuePair("title", title)); | |
| nameValuePairs.add(new BasicNameValuePair("caption", caption)); | |
| nameValuePairs.add(new BasicNameValuePair("key", IMGUR_API_KEY)); | |
| post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); | |
| HttpResponse resp = client.execute(post); | |
| if (resp.getStatusLine().getStatusCode() == 200){ | |
| return JSONObject.fromObject(EntityUtils.toString(resp.getEntity())).getJSONObject("upload").getJSONObject("links").getString("original"); | |
| } else { | |
| return "failure"; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment