Hi ben

I assume you know how to get request parameters, construct query strings and get a byte array from you db. Here's some code that will stream an image. This should get you far enough to adapt to you needs. if you use an action just return null instead of a forward, or just use a servlet. There was another way of doing this by creating a fascade so the possibility to get images in the way would always be possible, but I dont recall the details and although it was quite clever, the example i saw involved ugly code being added to html pages.

response.setContentType("image/jpeg");

String imageStr = "file:///image/foo.jpg";

OutputStream ou = response.getOutputStream();
java.net.URI imgUri = new java.net.URI(imageStr);
File imageFile = new File(imgUri);
RandomAccessFile raf = new RandomAccessFile( imageFile, "r" );
FileInputStream imageFileStream = new FileInputStream(imageFile);

//if you om returns a byte[] then you can probably start here.
byte[] image = new byte[(int) imageFile.length()];

while ( (raf.read( image )) > 0 ){
        ou.write( image );
}

ou.flush();
ou.close();

Cheers Mark


On 12 Feb 2004, at 12:30, Turner Benjamin wrote:


hello,

i am looking for a solution for the following problem:

in my database i have various BLOB items which represent images (gif or jpg). i would like to create a struts action which returns this (by passing along a request parameter to the action which is the imageid in the database. is it possible to set the response content/type in an action and then return the image itself somehow? maybe with a requestdispatcher? any ideas/pointers to this would be welcome.

ty,

Ben

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



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



Reply via email to