File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion 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

JPG�s from db and then deleting the files

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270

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


SCJP 1.4,
I agree. Here's the link:
subject: JPG�s from db and then deleting the files
It's not a secret anymore!