Hello, I am trying to write an image over an HttpURLConnection.
I know how to write text but I am having real problems trying to write an image
I have succeeded in writing to the local HD using ImageIO:
But I am trying to write Image by ImageIO on url and failed
URL url = new URL(uploadURL); connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setDoInput(true); connection.setUseCaches(false); connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); output = new DataOutputStream(connection.getOutputStream()); output.writeBytes("--" + boundary + "\r\n"); output.writeBytes("Content-Disposition: form-data; name=\"" + FIELD_NAME +
"\"; filename=\"" + fileName + "\"\r\n");
output.writeBytes("Content-Type: " + dataMimeType + "\r\n"); output.writeBytes("Content-Transfer-Encoding: binary\r\n\r\n"); ImageIO.write(image, imageType, output);
the uploadURL is the url to an asp page on the server which will upload the image with the file name given in "content-Disposition: part.
now when I send this then asp page find the request and find the name of file. but does not find the file to be uploaded.
The problem is that when writing by ImageIO on URL what will the name of the file on which the ImageIO is writing,
So please help me how ImageIO will write an image on URLConnection and how can I know the name of the file which I have to use in the asp page to upload the file
Thanks for taking the time to read this post Dilip Agarwal
Thanks for your time
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.