Storing images in DB vs in Folder Structure
Asked Answered
H

2

6

I understand it is possible to store images in Databases as Binary large objects. But I used to see in some forum web applications that they are stored as flat files in web server machine and retrieved when needed.

What is the advantage and disadvantage in both methods?

When to go for which approach?

Hackney answered 3/3, 2010 at 12:49 Comment(1)
There is very much discussions about this issue ...Orgel
G
12

As usual, it depends. You need to consider the usage pattern of the images and what features your DBMS provides.

Storing images in the database:

PROS

  • If the images are to be associated with entities in your database (say, a user), the database can take care of maintaining that relationship. If, on the other hand, images aren't associated to anything in the database, you will probably not want to store them in the database.
  • If your database supports it, you will be able to process files within a transaction (I believe MS SQL 2008 supports this, I don't know if others do).
  • If you need to store multiple versions of each image (say, because they change over time), it will probably be easier to do in the database than on the file system.

CONS

  • You will be putting a lot of strain on the database.
  • Backing up your database may take a long time.

Storing images on disk:

PROS

  • Making backups is trivial
  • Inspecting images etc. just requires a file browser, no need for a database client

CONS

  • Keeping the database's view of the image collection and the actual content on the disk in sync may be non-trivial, depending on the operations you will be performing on the images.

Of course, all these concerns are particularly valid if you store large numbers of images.

Ginni answered 3/3, 2010 at 13:8 Comment(0)
N
0

Flat files are better suited for representing images on web - they have much lower impact on server. OTOH they don't support transactions (actually you might do it with heterogenous transaction) and your data isn't in one place anymore.

Nowak answered 3/3, 2010 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.