我应该将图像作为二进制信息还是作为FS上的路径保存到数据库本身?

时间:2021-05-04 04:18:08

Background information:

背景资料:

This application is .NET 4/C# Windows Forms using SQLite as it's backend. There is only one user using the database and in no way does it interact through a network.

此应用程序是使用SQLite作为后端的.NET 4 / C#Windows窗体。只有一个用户使用数据库,绝不通过网络进行交互。

My software needs to save images associated to a Project record. Should I save the image as binary information in the database itself; or should I save the path to the picture on the file system and use that to retrieve it.

我的软件需要保存与项目记录关联的图像。我应该将图像保存为数据库本身的二进制信息;或者我应该保存文件系统上图片的路径并使用它来检索它。

My concerns when saving as path is that someone might change the filename of a picture and that would essentially break my applications use.

保存为路径时我担心的是有人可能会更改图片的文件名,这实际上会破坏我的应用程序使用。

Can anyone give some suggestions?interact through a network.

任何人都可以提出一些建议吗?通过网络互动。

3 个解决方案

#1


0  

First of all have you checked the SQLite limits? If this is of no concern for you application, I would still chose the FS for storage needs simply due to overhead from getting large BLOBS from DB vs. reading a file from FS. You can mark the files as read only and hidden to lessen the chance of them being renamed... You can also store the file hash (like MD5) of a file in the DB so you can have secondary lookup option in case someone does rename the file (of course, they could move it as well in which case this would not help much)...

首先,您检查了SQLite限制吗?如果这对您的应用程序无关紧要,我仍然会选择FS来满足存储需求,这主要是因为从DB获取大型BLOBS与从FS读取文件的开销。您可以将文件标记为只读和隐藏以减少重命名的可能性...您还可以将文件的文件哈希值(如MD5)存储在数据库中,以便在有人重命名时可以使用辅助查找选项该文件(当然,他们也可以移动它,在这种情况下,这将无济于事)...

#2


3  

"It depends". If there are a lot of images, then all that BLOB weight may make backups increasingly painful (and indeed, may preclude some database implementations that only support limited sizes). But it works, and works well. The file system is fine as long as you only store the path relative to some unknown root, i.e. you store "foo/blah/blip.png", which is combined with configuration data to get the full path - then you can relocate the path easily. File systems have simpler backup options in some cases, but you need to marry the file-system and database backups.

“这取决于”。如果有很多图像,那么所有BLOB权重都可能使备份变得越来越痛苦(实际上,可能会排除某些仅支持有限大小的数据库实现)。但它运作良好,效果很好。文件系统很好,只要您只存储相对于某个未知根的路径,即存储“foo / blah / blip.png”,它与配置数据结合以获得完整路径 - 然后您可以重新定位路径容易。在某些情况下,文件系统具有更简单的备份选项,但您需要将文件系统和数据库备份结合在一起。

#3


2  

In general, it is better to store them on the filesystem, with a path stored in the DB.

通常,最好将它们存储在文件系统中,并在DB中存储路径。

However, Microsoft published a white paper some time ago with research showing that files up to 150K can benefit from being put inside the DB (of course, this only pertains to SQL Server).

但是,微软不久前发表了一份白皮书,研究表明,高达150K的文件可以从放入数据库中受益(当然,这只适用于SQL Server)。

The question has been asked here many many times before:

这个问题之前已经多次提到过:

Exact Duplicate: User Images: Database or filesystem storage?
Exact Duplicate: Storing images in database: Yea or nay?
Exact Duplicate: Should I store my images in the database or folders?
Exact Duplicate: Would you store binary data in database or folders?
Exact Duplicate: Store pictures as files or or the database for a web app?
Exact Duplicate: Storing a small number of images: blob or fs?
Exact Duplicate: store image in filesystem or database?

完全重复:用户映像:数据库还是文件系统存储?完全重复:在数据库中存储图像:是或不是?确切重复:我应该将我的图像存储在数据库还是文件夹中?确切重复:您是否将二进制数据存储在数据库或文件夹中?完全重复:将图片存储为Web应用程序的文件或数据库?确切重复:存储少量图像:blob还是fs?精确复制:将图像存储在文件系统或数据库中?

#1


0  

First of all have you checked the SQLite limits? If this is of no concern for you application, I would still chose the FS for storage needs simply due to overhead from getting large BLOBS from DB vs. reading a file from FS. You can mark the files as read only and hidden to lessen the chance of them being renamed... You can also store the file hash (like MD5) of a file in the DB so you can have secondary lookup option in case someone does rename the file (of course, they could move it as well in which case this would not help much)...

首先,您检查了SQLite限制吗?如果这对您的应用程序无关紧要,我仍然会选择FS来满足存储需求,这主要是因为从DB获取大型BLOBS与从FS读取文件的开销。您可以将文件标记为只读和隐藏以减少重命名的可能性...您还可以将文件的文件哈希值(如MD5)存储在数据库中,以便在有人重命名时可以使用辅助查找选项该文件(当然,他们也可以移动它,在这种情况下,这将无济于事)...

#2


3  

"It depends". If there are a lot of images, then all that BLOB weight may make backups increasingly painful (and indeed, may preclude some database implementations that only support limited sizes). But it works, and works well. The file system is fine as long as you only store the path relative to some unknown root, i.e. you store "foo/blah/blip.png", which is combined with configuration data to get the full path - then you can relocate the path easily. File systems have simpler backup options in some cases, but you need to marry the file-system and database backups.

“这取决于”。如果有很多图像,那么所有BLOB权重都可能使备份变得越来越痛苦(实际上,可能会排除某些仅支持有限大小的数据库实现)。但它运作良好,效果很好。文件系统很好,只要您只存储相对于某个未知根的路径,即存储“foo / blah / blip.png”,它与配置数据结合以获得完整路径 - 然后您可以重新定位路径容易。在某些情况下,文件系统具有更简单的备份选项,但您需要将文件系统和数据库备份结合在一起。

#3


2  

In general, it is better to store them on the filesystem, with a path stored in the DB.

通常,最好将它们存储在文件系统中,并在DB中存储路径。

However, Microsoft published a white paper some time ago with research showing that files up to 150K can benefit from being put inside the DB (of course, this only pertains to SQL Server).

但是,微软不久前发表了一份白皮书,研究表明,高达150K的文件可以从放入数据库中受益(当然,这只适用于SQL Server)。

The question has been asked here many many times before:

这个问题之前已经多次提到过:

Exact Duplicate: User Images: Database or filesystem storage?
Exact Duplicate: Storing images in database: Yea or nay?
Exact Duplicate: Should I store my images in the database or folders?
Exact Duplicate: Would you store binary data in database or folders?
Exact Duplicate: Store pictures as files or or the database for a web app?
Exact Duplicate: Storing a small number of images: blob or fs?
Exact Duplicate: store image in filesystem or database?

完全重复:用户映像:数据库还是文件系统存储?完全重复:在数据库中存储图像:是或不是?确切重复:我应该将我的图像存储在数据库还是文件夹中?确切重复:您是否将二进制数据存储在数据库或文件夹中?完全重复:将图片存储为Web应用程序的文件或数据库?确切重复:存储少量图像:blob还是fs?精确复制:将图像存储在文件系统或数据库中?