问题描述
我正在 .NET 中编写一个上传函数,用于用户配置文件上的演示图像.我正在两种不同的方式之间进行选择,并想就利弊征询意见和建议.
I’m writing an upload function in .NET for presentation images on user profiles. I’m choosing between two different ways of doing it, and would like to ask on advice and opinions as to the pros and cons.
将图像直接存储在文件系统上
Store the images directly on the file system
将图像存储在数据库中
到目前为止,我主要是第一个选项 - 以用户名命名图像,因为每个用户只能拥有一个演示图像.然后我在指定的路径中检查用户是否有图像,如果没有则显示默认的无图像"-图像.
So far I’ve been mostly pro the first option – naming the images after the usernames, as each user can only have one presentation image. Then I do a check in the designated path if the user has an image, if not display a default "no image"-image.
我喜欢的另一件事是它节省了数据库中的空间——如果没有额外的二进制负载,数据库将会非常重.
Another thing I like about this is that it saves space in the DB – the DB will be pretty heavy without the extra binary load.
我确定还有其他方面我没有考虑过,所以我想听听您对此的看法.如果有人对此问题有完全不同的解决方案,也请分享!
I’m sure there are other aspects that I’ve not thought about, so I’d like to hear your opinions on this. If anyone’s got a radically different solution to the problem, please share that as well!
推荐答案
一般来说,最好将文件存储在文件系统上.文件系统已经针对存储文件进行了调整.但是,这确实有其缺点,特别是在管理、备份、恢复方面,并且在数据库中的 varchar 文件路径字段与文件系统中的文件之间存在某种脆弱的联系.你用的是什么数据库系统?我认为如果您使用的是 SQL Server 2008,那么新的 FileStream 类型为在该数据库中存储文件提供了一种非常好的方法.
In general, it is better to store files on the file system. File systems are already tuned for storing files. However, this does have its drawbacks, particularly in terms of management, backup, restore and it is somewhat of a flimsy tie between a varchar file path field in the database and a file in the file system. What database system are you using? I think if you are using SQL Server 2008, that the new FileStream type gives a very good method for storing files in that database.
请注意,我实际上是在更一般地谈论在数据库中存储文件.尝试将您打算在 HTML 页面上显示的图像存储在数据库中会涉及一些额外的复杂性.
Note I'm really talking about more generally about storing files in the database. There is some extra complexity involved in trying to store images you intend to display on HTML pages in the database.
这篇关于用户映像 - 数据库与文件系统存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!