0

I am uploading a image to back end and I want to display it on front end once the upload is complete. For doing this I am placing it under temp folder. The part I am unclear about it - how can I send this image to user browser?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Narendra
  • 5,635
  • 10
  • 42
  • 54

5 Answers5

0

maybe you can use uploadify it is very easy and you can upload multiple files at once. Check the demos http://www.uploadify.com/demos/

JoseP
  • 611
  • 3
  • 6
0

In your HTML file you need to use the img tag. If your picture is titled pic.jpg, you'd use something like:

<img src="temp/pic.jpg" alt="My incredible image.">

Zach Latta
  • 3,251
  • 5
  • 26
  • 40
0

Servlet would be very helpful for this. You do not need to store the image to a folder or anything, use the below steps. You should get the image in bytes using "java.io.InputStream", and send the stream as bytes and should use java.io.OutputStream, to read it and display it. Please check Input stream javadoc and Output stream javadoc for more clarifications. To send the image from client side to server side use the image upload in a form element, and submit the form to your servlet and use inputstream to receive the image bytes and give it to outputstream and return an outputstream. The sample code to display the image in bytearray.


byte[] imageBytes = getImageAsBytes(); response.setContentType("image/jpeg"); response.setContentLength(imageBytes.length); response.getOutputStream().write(imageBytes);

And finally give the url to your servlet returning an outputstream in the src attribute of the <img> tag <img src="url to your servlet">

You may also refer these.... 1.http://stackoverflow.com/a/1154279/1866662 2.http://stackoverflow.com/a/1264756/1866662

Imran
  • 26
  • 6
0
response.setContentType("image/jpg");
response.setHeader("Content-Disposition","inline;filename=filename.jpg");
-1

Are you trying to open a local image in the default web browser? if so, do:

java.io.File imageFile = new java.io.File("image.png");
java.awt.Desktop.getDesktop().browse(imageFile.toURI());

It will open the File Image to the default web browser.