wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes JPG�s  from db and then deleting the files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "JPG�s  from db and then deleting the files" Watch "JPG�s  from db and then deleting the files" New topic
Author

JPG�s from db and then deleting the files

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hi,

I have made a photo gallery.

1) First I read in the jpg�s as Blobs. For each Blob value I convert it to a BinaryStream which I write to a file ( FileOutputStream ).

2) Then I preview the jpg in a browser with the HTML tag <img src="PATH_TO_FILE.jpg">. I just make a reference to the directory and file...

That works fine!

The problem is that I don�t know how to delete all those files that I write
to the directory after reading the blob from the database.

Do I have to make a batch job to delete all the files or is it possible to show the jpg�s in the browser without writing the blob to a file first?
[ November 18, 2004: Message edited by: Jeppe ]
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
You can send an image to a browser without writing a file using a servlet. The response type of the servlet would be the image mime type (e.g. image/png for png files) and instead of writing the image data to a file output stream you would send it to the servlet's output stream.

in the servlet it might look something like this...



If you call this servlet as the URL for your image then the browser should display it

e.g.



SCJP 1.4, www.gsi3d.org.uk
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPG�s from db and then deleting the files