将图像(jpg、gif、png)存储在文件系统或数据库中? [英] Store images(jpg,gif,png) in filesystem or DB?

查看:33
本文介绍了将图像(jpg、gif、png)存储在文件系统或数据库中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
哪个更安全:文件系统还是数据库?
用户图像 - 数据库与文件系统存储
将图像存储在数据库或系统文件中?

我无法决定我应该关注哪一个.大家可以给点意见吗?我应该将图像存储在文件系统还是数据库中?(我想防止别人盗用我的图片)

I can't decide which one I should follow. Can you guys give some opinions? Should I store my images in the file-system or DB? (I would like to prevent others from stealing my images)

回答这个问题时,请包括安全性、性能等方面的比较

When you answer this question, please include comparisons of the security, performances etc.

谢谢.

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

推荐答案

将图像移动到数据库中并编写代码来提取图像可能会比它的价值更麻烦.这一切都将回到围绕保护图像的需求或性能要求的业务需求.

Moving your images into a database and writing the code to extract the image may be more hassle than it's worth. It will all go back to the business requirements surrounding the need to protect the images, or the requirement for performance.

我建议坚持使用久经考验的真实系统,将文件路径或目录位置存储在数据库中,并将文件保存在磁盘上.原因如下:

I'd suggest sticking to the tried and true system of storing the filepath or directory location in the DB, and keeping the files on disk. Here's why:

  • 文件系统更易于维护.必须对图像的结构和组织进行一些思考.即每个客户的目录,每个 [Attribute-X] 的子目录和每个 [Attribute-Y] 的另一个子文件夹.在一个目录中保存太多图像最终会减慢文件访问速度(即数十万)
  • 如果将存储在数据库中的想法是针对文件系统丢失的对策(即磁盘损坏或目录被意外删除),那么我会反驳以下建议:当您使用源代码控制时,找回任何丢失/丢失/删除的文件都没有问题.
  • 如果您需要扩展并转移到内容分发场景,则必须移回文件系统或执行大量提取以推送给提供商.
  • 俗话说:将结构化数据保存在数据库中".Microsoft 有一篇关于管理非结构化数据的文章.
  • 如果安全性是一个需要解决的问题,文件系统有一个带有 ACL 的完整结构.在安全方面重新发明轮子可能超出了业务要求的范围.

关于此主题的大量讨论也可以在以下位置找到:

A large amount of discussion for this topic is also found at:

将您的图像存储为 varbinary 或某种类型的 blob(取决于您的平台),我建议它比它的价值更麻烦.您需要扩展的工作量意味着您需要维护、单元测试和防御缺陷的更多代码.

Having your images stored as varbinary or a blob of some kind (depending on your platform), I'd suggest it's more hassle than it's worth. The effort that you'll need to extend means more code that you'll have to maintain, unit test, and defend against defects.

如果您的环境可以支持 SQL Server 2008,那么您可以通过 SQL 2008 中的新 FileStream 数据类型获得两全其美.

If your environment can support SQL Server 2008, you can have the best of both worlds with their new FileStream datatype in SQL 2008.

  • An MSDN article is touting the FileStream datatype in SQL 2008 as high performance.
  • SQL Skills has a great article with some SQL 2008 Filestream performance measurements.
  • Here is an article addressing varbinary vs. FileStream and performance of both datatypes.
  • If you are a SQL Mag subscriber, you can see a great article at SQL Mag on SQL 2008 FileStream.
  • Microsoft Research article:To Blob or Not To Blob

我很乐意看到在真实场景中进行的研究,这些研究拥有 Flickr 或 Facebook 等庞大的用户群.

I'd love to see studies in real-world scenarios with large user bases like Flickr or Facebook.

同样,这一切都可以追溯到您的业务需求.祝你好运!

Again, it all goes back to your business requirements. Good luck!

这篇关于将图像(jpg、gif、png)存储在文件系统或数据库中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆