I need to upload my image to localhost(I mean, I need to specify the destination location in terms of http like http://localhost:8080/somelocation). I need code for this in java.
I need to upload my image to localhost(I mean, I need to specify the destination location in terms of http like http://localhost:8080/somelocation). I need code for this in java.
This is a forum, not a code mill. Post your best efforts and ask a specific question, and there are many here who will try to help you.
db
Sorry! I am very new to java. I just followed the thread (http://www.java-forums.org/java-appl...oad-image.html) I didnt got errors, it seems to be working fine. But I didnt got the image copied in the destination. So can u please guide me in particular direction.
Hi this is my code, I am trying to send image in my filesystem to tomcat server running at port 8080. While running this code, I am not getting any exception. But I didnt got the image in my destination.
String uploadUrl = "http://localhost:8080/images";
String targetFileName = "blue.jpg";
URL url;
HttpURLConnection connection = null;
try {
//Create connection
url = new URL(uploadUrl);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "image/png");
connection.setRequestProperty("Target-File-Name", targetFileName);
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//Send request
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
Image i = Toolkit.getDefaultToolkit().getImage("/blue.jpg");
BufferedImage bimg = new BufferedImage (i.getWidth(100), i.getHeight(130), BufferedImage.TYPE_INT_ARGB);
bimg = (BufferedImage)i;
ImageIO.write(bimg, "png", wr);
wr.flush ();
wr.close ();
//Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
No replies yet! Its urgent, somebody help me pls.....