By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,797 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,797 IT Pros & Developers. It's quick & easy.

images, writing over url connection

P: n/a
Hello, pretty new to java so bear with me.

I am trying to write an image over an HttpURLConnection.

I have an example of how to write text but I am having real problems trying
to write an image, just can't get my head around it.

I have succeeded in writing to the local HD using ImageIO:
//start image output
FileOutputStream fo = new FileOutputStream("myImg.jpg");
BufferedOutputStream bo = new BufferedOutputStream(fo);
ImageIO.write(destination, "jpeg", bo);
bo.close();
//end image output

This works a treat. I understand how to set up an url connection and then
write text to it:

//start text to url
URL url = new URL( "http://www.myurl.com/myfolder/aFile.cfm" );
HttpURLConnection urlcon = (HttpURLConnection) url.openConnection( );

urlcon.setRequestMethod("POST");
urlcon.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
//image/jpeg

urlcon.setDoOutput(true);
urlcon.setDoInput(true);

PrintWriter pout = new PrintWriter( new
OutputStreamWriter(urlcon.getOutputStream( ), "8859_1"), true );

pout.print( formData );//form data collected from app
pout.flush( );
// end text to url

What I am having a problem with is this bit:
PrintWriter pout = new PrintWriter( new
OutputStreamWriter(urlcon.getOutputStream( ), "8859_1"), true );

Where I want to put in my buffered output stream, and then use that with
ImageIO, I just can't see where I am supposed to start.... or have I missed
the boat entirely

Thanks for taking the time to read this post.
cheers
Martin

Thanks for your time
--

---------------
http://www.nonstoploop.co.uk/ - dynamic websites
http://www.rossanobacchin.be/ - fine art
http://www.weycameras.co.uk/ - photographic supplies
---------------

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.