The other day I thought about the storage of images. There are two alternatives: in the file system and in the database. This is me, by the way, about images for web projects.
I read the literature. As it turned out, but it was not particularly surprising, storing files as files has several advantages:
Speed. Perhaps one of the most important advantages. The fact is that when storing in the database we need to perform the following actions to display the image: read the stream from the database, create a temporary file, write the stream to it. From the file system, it is enough to read it.
Versatility. Regular images can be used for many applications: send via ftp, add to email, show in browser. Binary data from the database must first be converted.
Ease of implementation. Uploading a file to the server and saving the link to it in a table is easier than implementing the logic of saving binary data in the same table. And simplicity is the speed of developing and making changes. Time is money.
And if the base suddenly collapses (imagine that there were no backups), then at least the images will not be lost.
File storage in the database has one undoubted advantage - encryption. But is it often necessary to take such precautions for images? And it is quite difficult to synchronize the file system with the database: deleted the record, you need to delete the file as well. In the database, the same is solved in one move by cascading deleting the corresponding entry with the BLOB.
In a number of questions, none of the approaches have any clear advantages. For example, backup can be done both for the database and for the file system. ')
The verdict is. It is not that any of the approaches is more correct, because correctness is determined by the task. More simple is the standard way to store images as files. But for some tasks, databases are more suitable.