Question:
Best way for image management C#/asp.net?
1970-01-01 00:00:00 UTC
Best way for image management C#/asp.net?
Three answers:
?
2016-02-29 01:51:38 UTC
O.o
Gardner
2011-12-26 17:34:08 UTC
Storing image data in your database is not usually the best method. It makes your database huge. Make a special folder for each realtor that images can be uploaded to and in your database just have a link to the file.
MT
2011-12-26 18:46:21 UTC
Storing images in DB is not always a bad choice. Storing image in database has the benefit of:



- Ease of backup. You'll backup the images along with the database.

- Sync of data. You do not need to worry about file system changes, missing files, unreferenced file etc.



I don't see a problem with huge database size. Sure, it is taking longer to backup, but considering that file size remains the same no matter where it is saved, you'll still backing up the same amount of data when you're doing a backup, unless you're doing an incremental backup (which is also one of the benefit of saving files in FS).



According to the research "To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem?", there is performance advantage on FS when the object is larger than 1 MB, and advantage on DB when the object is smaller than 256 kb. Within the range, it depends on how often the file will be modified. So, you may put this into consideration when making your decision.



For ASP.Net, you'll be using the FileUpload control. To save a file in your file system, call the SaveAs(string) method. You'll need to provide the location that you want to save the file to. This location will also be saved in your database for reference. To delete the file, just use the System.IO.File.Delete(string) method.



To save a file into database, you'll need to get the byte array of the file, which can be done by accessing the FileBytes property of the control. To save the file to the database, just pass the byte array as a parameter to your insert query. To delete the file, just run a simple delete query.



Hope this helps.



Here are some references if you have the time to take a look:

http://research.microsoft.com/apps/pubs/default.aspx?id=64525

http://databases.aspfaq.com/database/should-i-store-images-in-the-database-or-the-filesystem.html

http://www.onlineaspect.com/2007/07/10/image-storage-database-or-file-system/

http://www.extremeexperts.com/SQL/FAQ/StoreImages.aspx

http://blogs.msdn.com/b/brian_swan/archive/2010/03/25/store-images-in-the-database-or-file-system.aspx


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...