Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Problem with storing an image into database!!!

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Posts: 43016
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic