Forum Stats

  • 3,839,770 Users
  • 2,262,532 Discussions
  • 7,901,053 Comments

Discussions

Images writing over URLConnection

835813
835813 Member Posts: 7
edited Feb 4, 2011 7:20AM in Java Programming
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 + "");
output.writeBytes("Content-Disposition: form-data; name=\"" + FIELD_NAME +

"\"; filename=\"" + fileName + "\"");

output.writeBytes("Content-Type: " + dataMimeType + "");
output.writeBytes("Content-Transfer-Encoding: binary");
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

Edited by: user10922333 on Feb 2, 2011 8:51 PM
Tagged:

Answers

  • EJP
    EJP Member Posts: 32,920 Gold Crown
    I know how to write text but I am having real problems trying
    to write an image
    It's exactly the same. Read bytes from the source and write them to the destination.
    I have succeeded in writing to the local HD using ImageIO:
    You don't need to use ImageIO unless you are performing conversions between formats. Just use the connection's output stream.
    EJP
  • 835813
    835813 Member Posts: 7
    but how can i read these bytes from asp script. and then recreate the image by it
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    You're already reading bytes with the ASP script. Nothing has changed. But if you are starting with an image you have to use ImageIO. But all that does is write bytes same as above. The filename problem seems to be something wrong with your multipart HTTP headers.
    EJP
  • 835813
    835813 Member Posts: 7
    actually I have less knowledge of asp, so can you give me some code of asp or concept so that asp classic can read read these bytes, because I am able to find the things like content-type and other header fields but not the bytes write by the ImageIO is there any thing special to read these bytes please give some code

    Thanks for your reply
    Dilip Agarwal
This discussion has been closed.