File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Problem with storing an image into database!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Problem with storing an image into database!!!" Watch "Problem with storing an image into database!!!" New topic

Problem with storing an image into database!!!

pavan kumarthati

Joined: Feb 21, 2009
Posts: 3
I have a doubt about which is the best approach to store image [ whether to store image in web server directory or in the database]...Any ans is appreciative....
please concern the efficiency and security issues..
ujjwal soni
Ranch Hand

Joined: Mar 28, 2007
Posts: 403
Hi Pavan,

It depends on the website load ie: the number of users accessing the website daily. Well, concerning about the security, the best way would be storing image as a blob inside a database (if your website load is minimum). If you have maximum load on website like those of yahoo/orkut then the best way would be clustering the database server & store image in a distributed way.


Ujjwal B Soni

Ujjwal B Soni <baroda, gujarat, india> <+918866008962>
"Helping hands are better than praying lips......"
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Load is certainly not an issue, in both cases it's just streaming some bytes from the one to the other side. Security is also not an issue, in both cases you can just configure security levels yourself.

Portability, shareability and searchability are more an issue. Storing images in a DB improves portability, but decreases shareability. Storing only raw binary data in a DB without any additional information decreases searchability. Side-storing file attributes like content type, file length, last modification time, etcetera in the database improves searchability, but that could better be done if you store the files in filesystem and only the path and/or filename in the database. You could use to obtain file attributes.

Weigh the pros and cons yourself.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
In general I'd keep files out of the database, unless there are numerous attributes that you need to store and retrieve with them.

Using the file system raises issues of concurrency, though, so if the files are updated frequently (as opposed to read-only), it may not be easy to guard against that. That's be much simpler using a DB.

I wouldn't say that security is not an issue. Access control on the server is a matter of configuration, but the application logic that deals with who gets to access which files needs to be coded, and that may well be simpler for one approach compared the other. I agree that it likely is not the deciding factor, though.
I agree. Here's the link:
subject: Problem with storing an image into database!!!
It's not a secret anymore!