Re: Read image from database
Don Albertson <[email protected]>
| Newsgroups | gmane.comp.jakarta.taglibs.user |
|---|---|
| Message-ID | <[email protected]> |
Zilberstein Yuval wrote: > Hello, > Can anyone tell me how do I read an image from a Blob field in the > database? > > TX > YuvalZ > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > I haven't put any of this into tags but.... My experience is limited to our Oracle system. I created two classes: One wraps the Oracle implementation code and avoids the need to import oracle.sql.BLOB; import oracle.jdbc.OracleResultSet; in places that are isolated from driver implementation details Another converts the BLOB's to and from Image and byte[] so I can display them. For the web side, I adapted a servlet to display the image using this fragment: byte[] imageData = image.getImageBytes(); if ( imageData != null && imageData.length > 0){ response.setContentType("image/jpeg"); ServletOutputStream sos = response.getOutputStream(); sos.write(imageData); } I only save a thumbnail in the database as a BLOB so the thumbnail is the only image being returned in the response stream.