Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is good Practice storing a uploaded File in DB or storing it in Filesystem

I have a File Uploader in my ASP.NET application Using C#, we can upload any type like images, documents, pdf etc.

I m storing it in the Filesystem and having only the Name of the File in DB. My doubt is can we store the entire file, images in DB. State me Which is good practice and why we need to use it.

Either file System Storage or SQL DB Storage.

like image 472
Fairy_G Avatar asked May 11 '10 06:05

Fairy_G


People also ask

Is it better to store files in database or filesystem?

Database provides a proper data recovery process while file system did not. In terms of security the database is more secure then the file system (usually). The migration process is very easy in File system just copy and paste into the target while for database this task is not as simple.

Is it a good practice to store files in database?

Reasons in favor of storing files in the database:Having the files and database in sync and able to participate in transactions can be very useful. Files go with the database and cannot be orphaned from it. Backups automatically include the file binaries.

Is it better to store images in database or filesystem?

Generally databases are best for data and the file system is best for files. It depends what you're planning to do with the image though. If you're storing images for a web page then it's best to store them as a file on the server. The web server will very quickly find an image file and send it to a visitor.

Why use databases and not store data in files?

Security. While access to text files or spreadsheets can be secured, once someone has access to a file, they have access to all data within that file. Databases can be made very secure, and that includes the ability to have access rights to specific parts of the database and not others.

Why storing files in the database is considered bad practice?

Storing files in the database slows down overall query performance simply because there is more data transmitted between the application and the database. Additionally, files use up RAM which is used internally by the database to improve performance.


2 Answers

Almost the same question was asked here. Check the answer:

Working with images in WCF

It mostly depends on the size of your files. Here's a nice article.

To BLOB or Not To BLOB

For less than 256kb files storing in DB in VarBinary column is more efficient.

We store our files in MS SQL Server in a VarBinary column with 256kb restriction and it works fine.

Hope it helps. Good Luck!

like image 174
hgulyan Avatar answered Sep 21 '22 01:09

hgulyan


This is argumentative subjective, but I would say that storing files on the files system is better. That's what file systems are designed for and SQL Server 2008 has a new file type that allows you to do this automatically and even use transactions.

like image 41
Darin Dimitrov Avatar answered Sep 22 '22 01:09

Darin Dimitrov