Results 1 to 5 of 5
- 10-29-2010, 11:13 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
Image upload from file system to local host (server) through http protocol 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.
- 10-29-2010, 11:22 AM #2
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
- 10-29-2010, 11:52 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
Sorry! I am very new to java. I just followed the thread (Upload an image.) 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.
- 10-29-2010, 12:55 PM #4
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
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();
- 10-30-2010, 10:16 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
upload file from local system to database
By harsha.udupa2008 in forum Advanced JavaReplies: 3Last Post: 09-17-2010, 08:58 AM -
copy file from local host to remote host
By isotoper in forum New To JavaReplies: 4Last Post: 12-24-2009, 04:41 PM -
:large file upload to server(chunk upload)
By tommy_725 in forum NetworkingReplies: 0Last Post: 10-16-2009, 12:21 AM -
Accessing local file from server side using Java Application
By ersachinjain in forum JDBCReplies: 9Last Post: 09-01-2009, 07:17 PM -
How to read xml file located in local system using Java
By java_kick in forum Advanced JavaReplies: 2Last Post: 04-06-2009, 11:28 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks