Store pictures as files or in the database for a web app?

StefanE picture StefanE · Feb 18, 2009 · Viewed 44.6k times · Source

My question is fairly generic and I know there might not be an 100% answer to it. I'm building an ASP .NET web solution that will include a lot of pictures and hopefully a fair amount of traffic. I do really want to achieve performance.

Should I save the pictures in the Database or on the File system? And regardless the answer I'm more interested in why choosing a specific way.

Many thanks, Stefan

DUPLICATE: Storing Images in DB - Yea or Nay?, How to store images in your filesystem, Storing a small number of images: blob or fs? and probably some others.


COMMENT: Thanks for many good answers. I will go for a file based solution even if I like the idea of having a 100% database driven solution. It seems that there are today good solutions to do what I want with databases etc but I have a few reasons for not doing it.

  • I will be on a hosted solution, I have huge amount of storage(10gb) but only 300mb for the database. It will cost a lot for extra storage in the DB.

  • I'm not an DB expert and as well not in control of settings of the DB. A DB based solution might need custom configuration as it looks like.

If we will move to run the site on our own server I might consider a DB based solution. thanks, Stefan

Answer

Akbar ibrahim picture Akbar ibrahim · Feb 18, 2009

Store the pictures on the file system and picture locations in the database.

Why? Because...

  1. You will be able to serve the pictures as static files.
  2. No database access or application code will be required to fetch the pictures.
  3. The images could be served from a different server to improve performance.
  4. It will reduce database bottleneck.
  5. The database ultimately stores its data on the file system.
  6. Images can be easily cached when stored on the file system.