Re: Display images on a webpage



Kevin Moseley wrote:
I apologize for not being clearer. I am new to java,struts, tomcat, and hibernate. I guess I am curious as to which is better, storing images in a database or using the file system and storing the file information in the database. What I want to do is have users upload photos and when they open their profile they can view the files they have uploaded. I am using struts and hibernate and I don't know how to pull multiple images in the jsp.
What is the best practice for uploading and viewing images? I have googled it and it seems the consensus is to store files on the file system and use action files to display the images using input streams to display the images. What is causing me problems how to display on the page load.
When I meant reload is if upload a new .war file doesn't is overwrite the folder when I restart tomcat and if my images were in there they would be lost.

You can store the images 3 places:
a) database
b) file system in directory served by Tomcat
c) file system in directory not served by Tomcat

It can be implemented by:
a) have your pages generate <img src="ImageServlet?imgid=177">
have ImageServlet set MIME type appropriate, retrieve BLOB from
database and write to output
b) have your page generate <img src="images/img177.jpg">
c) have your pages generate <img src="ImageServlet?imgid=177">
have ImageServlet set MIME type appropriate, read image from
file system and write to output

Which one to chose ?

#b has some problems:
- redeployment that you mention
- lack of security by user
so it is either #a or #c.

It is a well known discussion.

Many people swear that images in the database will kill the
database performance.

And putting images in an Access 95 database on Windows 95 on
a 150 MHz Pentium box indeed did kill database performance.

But a few things ha changed in software and hardware since then.

With a good database system then there should not be any problem
having images of small-medium size in the database.

I once made som tests to verify and performance was OK.

So I will suggest going for #a.

Arne
.



Relevant Pages

  • Re: [PHP] Re: how to display images stored in DB*
    ... Your claim is that in ALL cases using a file system to store images ... bitmaps in a database without a damn good reason, a bad practice, yes. ...
    (php.general)
  • Re: ASP Hotspots
    ... my images are in the file system with the path referenced from an ... Access field. ... They go in the file system and the path to load them is stored ... > in the database. ...
    (microsoft.public.frontpage.programming)
  • Re: Upload Problem Using ASP
    ... administration form offline to the offline database, ... certain field i made in database. ... I can read images names by the same way, do u have anyway to complete ... > make a small visual basic program to upload the database and the images to ...
    (microsoft.public.inetserver.asp.general)
  • Re: Storing images in folder or database?
    ... file system and then have some table that tracks filenames and associates to ... an object in the database. ... You have to structure the transaction during the upload. ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: [PHP] Re: how to display images stored in DB
    ... Images are typically best supported in the form of files. ... database is not a good idea. ... Databases implement their own filesystem for the most parts. ... A data storage system within a file system. ...
    (php.general)