I'm developing a web app using Struts 1.2, Hibernate 3.0 and MySQL 5 and I can properly upload images into the DB, but the problem is that I do not know how to restore them and display them bak on a web page.
I've tried some code like this in my UploadFileAction class:
// Get the image Blob from the database
Blob blob = rs.getBlob( 1 );
InputStream in = blob.getBinaryStream();
// Output the blob to the HttpServletResponse
res.setContentType( "image/jpeg" );
BufferedOutputStream out = new BufferedOutputStream( res.getOutputStream() );
byte by[] = new byte[ 32768 ];
int index = in.read( by, 0, 32768 );
while ( index != -1 )
{
out.write( by, 0, index );
index = in.read( by, 0, 32768 );
}
out.flush();