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.
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.
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.
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.
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With