Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Image Read from Blob  RSS feed

 
Karthik Kris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

We have images stored in a Blob in Oracle Database. I was able to retrieve the bytes of the images from the blob. However in the response output I get a screen of binary characters.

I tried r
response.setContentType("image/gif");

as well. In this scenario it shows me a image place holder on the screen. No image is displayed here as well.

Bytes are read fine from the database.

I am using Oracle application server 10 g env.


Thanks
Karthik
 
Sharath Punreddy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using IMG tag on the jsp with SRC as a servlet.
The servlet should have the following code for reading the image:

res.setHeader("Cache-Control","no-cache"); //HTTP 1.1
res.setHeader("Pragma","no-cache"); //HTTP 1.0
res.setDateHeader ("Expires", 0); //prevents caching at the proxy server
res.setContentType("application/octet-stream");

java.io.OutputStream outs = res.getOutputStream();
java.io.ByteArrayInputStream in = new java.io.ByteArrayInputStream(photo);

int b;
while((b=in.read())!=-1){
outs.write(b);
}
outs.flush();
outs.close();
in.close();
 
Karthik Kris
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I tried the above and still things are not working.

I also noticed a strange and interesting behavior while testing this.

The bytes I read from the blob I re directed to File Output Stream and wrote a Image File . Image file was created in the directory I specified.

Image file was read perfectly by MS PAINT . However the IE shows just a image place holders. Please help me regarding this

Is there any metadata I need to write image header or just having response content type image/jpeg along would suffice.


Karthik
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!