I'm trying to send an image to Imgur but it's giving error, I can not remember how I get the image. I'm using this code:
public static String getImgurContent() throws Exception {
URL url;
url = new URL("https://api.imgur.com/3/image");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
String data = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(IMAGEM_AQUI, "UTF-8");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Authorization", "Client-ID " + "000000000");
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
conn.connect();
StringBuilder stb = new StringBuilder();
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
stb.append(line).append("\n");
}
wr.close();
rd.close();
return stb.toString();
}
Well, it has this IMAGEM_AQUI
, when I put a link of an image type http://i.imgur.com/38KP393.png
it works normally. But I wanted to know how do I get an image of my project or an object of type Image
or BufferedImage
when I try to put only the name type "imagem.png"
it does not work ...