Store images in database or on file system [duplicate] Store images in database or on file system [duplicate] database database

Store images in database or on file system [duplicate]


Personal opinion: I ALWAYS store images on the file system, and only store a filepath in the database. In many situations, databases are stored on fast (read: expensive storage, 15k RPM or SSD drives) storage. Images or other files, typically can be stored on slower (read: cheaper, larger drives, 7.2k RPM drives) storage.

I find this to be the best, since it allows for the database to remain small in size. In general, databases store "data" well. They can search and retrieve small bits of data fast. File Systems store "files" well, they are optimized to find and retrieve larger bits of data fast.

Obviously there are tradeoffs to both approaches, and there isn't going to be a one-size fits all; however, there may be some use cases where storing images in the database is a good thing, if they are all quite small, and you don't anticipate very many of them, and your database is on the same storage medium as your file share, then it probably makes sense to drop the images directly into the database.

As a side note, SQL Server 2008R2 has a FileStream field type, which can provide the best of both worlds, I have not used it yet, so I can't speak to how well it works.


Store files/images in the database if you require following:

  • Access Control
  • Versioning
  • Checkin/Check out
  • Searching based on metadata

That has been the design of major CMS like SharePoint has been.

However, if your content is much more static and not going to change over time , you can go with files ystem and enable optimizations/cache on the web server.


With the database approach, you only have one thing to connect to. If your users are distributed, that might be simpler. Note that if the images are not accessed too frequently, the efficiency issues might not matter.