Should I Save Images to Database or File System
It's been an issue for some time for developers the question of whether to save images on database or on file system. I decided to write this article to explain the pros and cons of both sides.
Saving Images To File System
Saving images to file system seems to be the best approach for some reasons. Images stored on file systems are easy to manage. When you need to retrieve the images, you just retrieve the path from your database and then load the image from there. They can also be easily previewed and this method separates your database information from image data. The down side of using file system to store images are the following:
* File system images can easily be renamed or deleted.
* File system images are susceptible to virus corruption (especially if you are running Windows)
* If your application is a web application, additional security measures must be done to secure images from unauthorized copying, linking etc...
Saving Images To Database
Images stored on database tables is applicable for images where database size is not a major concern, usually for applications which is expected to have just a minimum amount of information and would not require large concurrent connections. This gives you a centralized storage for all your applications resources. But for application which requires large amount of information, the database approach must be avoided for the following reasons:
* Saving images to tables bloats your database reducing performance
* Storing and retrieving images to tables requires additional programming techniques for converting images to byte array data and vice-versa.
* Images on database cannot be easily previewed.
* Dump files for your SQL Tables would consume large disk space.
* When databases are not well-structured and not maintained properly, bulky images can cause table/database corruption.
It is up to you whether to use the file system or the database approach. To me, I usually prefer the file system approach.