I'm using DB2 with pictures stored as blobs. We have a system similar to what Wendy suggested. When the image is retrieved from the database it is sent to an image servlet that will cache the image. The browser then asks the image servlet for the image. The image servlet is also smart enough to ask the database for the image if it finds it is not available in the cache. I tried to write it flexibly enough so that the size of the image cache and the the amount of time an image stays in cache is flexible. Also, if this system becomes too slow we should easily be able to switch to a file system approach.

Good luck,

Ross

Braun, James F wrote:

Goal: Read a blob image from an Oracle database and render it on an html
page using the struts framework.

I've never found a good way to do this and I was hoping someone had a
"best practice" suggestion.

I have no trouble getting the image from the database. However, I wonder
if there isn't a better way to display it rather than writing it to a
physical file and then rendering it. I'm using the <html:img tag to
display the image now.

All help appreciated.

J.

ImputStream pictureStream;
ResultSet rs;

// create the query and execute it ...

// get the result
pictureStream = rs.getBinaryStream("picture");

// I can write it to a physical file
File pictureFile = new File("/temp/picture.jpg");

       try
       {
         FileOutputStream out = new FileOutputStream(pictureFile);
         int chunk = 0;
         while( (chunk = pictureStream.read()) != -1)
         {
           out.write(chunk);
         }
         out.close();
         out.flush();
       }
       catch(FileNotFoundException ex)
       {
         System.err.println("selectionForm.populate.picturefile: " +
ex.getMessage());
         logger.error("selectionForm.populate.picturefile: " +
ex.getMessage());
       }
       catch(IOException ex)
       {
         System.err.println("selectionForm.populate.picturefile: " +
ex.getMessage());
         logger.error("selectionForm.populate.picturefile: " +
ex.getMessage());
       }


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to