7

Possible Duplicate:
Storing Images in DB - Yea or Nay?

Is it faster and more reliable to store images in the file system or should I store them in a database?

Let's say the images will be no larger than 200 MB. The objective is fast, reliable access.

In general, how do people decide between storing files (e.g., images, PDFs) in the file system or in the database?

Community
  • 1
  • 1
Crashalot
  • 33,605
  • 61
  • 269
  • 439

4 Answers4

15

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.

Nate
  • 30,286
  • 23
  • 113
  • 184
  • Well written -- and pointing out that some databases have provisions for accessing out-of-database-primary data. –  Dec 28 '10 at 23:09
5

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.

Madhur Ahuja
  • 22,211
  • 14
  • 71
  • 124
  • If I only need Access Control, is it possible to perform Access Control with the webserver and the filesystem (and thus avoiding to store the images in the database)? How to do that? – yves Baumes Mar 16 '21 at 16:38
1

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.

davep
  • 286
  • 1
  • 4
0

First of all you must know that in databases, you can't store files bigger than i think 8 mb, leavinig that, so i think is better to store files in the system, and small images in the database

Carlos Valenzuela
  • 816
  • 1
  • 7
  • 19
  • 2
    This depends on the database. SQL Server can store up to 2GB (or perhaps "just" 1GB?). –  Dec 28 '10 at 23:07