所以我用的是一个在数据库中大量存储图像的应用程序。你对此有什么看法?我更倾向于将位置存储在文件系统中,而不是直接存储在DB中。

你认为优点和缺点是什么?


当前回答

I'm not sure how much of a "real world" example this is, but I currently have an application out there that stores details for a trading card game, including the images for the cards. Granted the record count for the database is only 2851 records to date, but given the fact that certain cards have are released multiple times and have alternate artwork, it was actually more efficient sizewise to scan the "primary square" of the artwork and then dynamically generate the border and miscellaneous effects for the card when requested.

这个图像库的最初创建者创建了一个数据访问类,它根据请求呈现图像,并且对于查看和单独的卡片来说,它的速度非常快。

This also eases deployment/updates when new cards are released, instead of zipping up an entire folder of images and sending those down the pipe and ensuring the proper folder structure is created, I simply update the database and have the user download it again. This currently sizes up to 56MB, which isn't great, but I'm working on an incremental update feature for future releases. In addition, there is a "no images" version of the application that allows those over dial-up to get the application without the download delay.

到目前为止,这个解决方案工作得很好,因为应用程序本身被定位为桌面上的单个实例。有一个网站将所有这些数据存档,以供在线访问,但我绝不会使用相同的解决方案。我同意文件访问更可取,因为它可以更好地适应图像请求的频率和数量。

希望这不是太多的废话,但我看到了这个主题,并想从一个相对成功的中小型应用程序中提供一些我的见解。

其他回答

如果这是基于web的应用程序,那么将图像存储在第三方存储交付网络(如Amazon的S3或Nirvanix平台)上可能会有优势。

数据数据库

文件的文件系统

将图像存储在文件系统中的另一个好处是,您不需要做任何特殊的事情来让客户端缓存它们……

...当然,除非图像不能通过文档根访问(例如身份验证障碍),在这种情况下,你需要检查你的代码正在发送的缓存控制头。

我会选择两种解决方案,我的意思是……我将开发一个小组件(EJB),它将映像存储在DB中,并将映像存储到服务器的路径。只有当我们有一个新的图像或原始图像更新时,这个DB才会更新。然后,我还将该路径存储在业务DB中。

从应用程序的角度来看,我将始终使用文件系统(从业务DB检索路径),通过这种方式,我们将修复备份问题,并避免可能的性能问题。

唯一的缺点是我们将存储相同的图像2次…好的一点是内存很便宜,拜托!

在数据库中只存储映像的文件路径的问题是,不能再强制数据库的完整性。

如果文件路径所指向的实际映像变得不可用,则数据库会不知不觉地出现完整性错误。

考虑到图像是被寻找的实际数据,并且它们可以在一个集成的数据库中更容易地管理(图像不会突然消失),而不必与某种文件系统(如果文件系统是独立访问的,图像可能会突然“消失”),我倾向于将它们直接存储为BLOB或类似的文件系统。