2
I’m trying to send an image to Imgur but it’s giving error, I can’t remember how to 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, there’s this one IMAGEM_AQUI
, when I put a link of a type image http://i.imgur.com/38KP393.png
works normally. But I was wondering how do I get an image of my project or an object of the type Image
or BufferedImage
when I try to put just the name like "imagem.png"
it doesn’t work...