Storage of images in the database and in the folder structure

I understand that you can store images in Databases as binary large objects. But in some forum web applications, I saw that they are stored as flat files on the web server and retrieved when necessary.

What are the advantages and disadvantages of both methods?

When to go for which approach?

+4
source share
2 answers

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

Saving images in a database:

PROFI

  • If images need to be associated with objects in your database (for example, by the user), the database can take care of maintaining this relationship. If, on the other hand, the images are not associated with anything in the database, you probably will 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 that MS SQL 2008 supports this, I do not know if others do).
  • If you need to store several versions of each image (say, because they change over time), this will probably be easier to do in the database than in the file system.

REDD

  • You will heavily load the database.
  • Backing up a database can take a long time.

Saving images to disk:

PROFI

  • Creating backups is trivial
  • Image verification, etc. only requires a file browser, no database client needed

REDD

  • Keeping the database view of the image collection and the actual contents on disk in sync may not be trivial, depending on the operations you will perform on the images.

Of course, all these problems are especially relevant if you store a large number of images.

+6
source

Flat files are better suited for presenting images on the Internet β€” they have a much lesser impact on the server. OTOH they do not support transactions (in fact, you can do this with a heterogeneous transaction), and your data is no longer in one place.

0
source

Source: https://habr.com/ru/post/1302987/


All Articles