要做或不做:将图像存储在数据库中 [英] To Do or Not to Do: Store Images in a Database

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

问题描述

在 Web 应用程序的上下文中,我的老老板总是说在数据库中放置对图像的引用,而不是图像本身.我倾向于同意将 url 与图像本身存储在数据库中是个好主意,但我现在工作的地方,我们在数据库中存储了很多图像.

In the context of a web application, my old boss always said put a reference to an image in the database, not the image itself. I tend to agree that storing an url vs. the image itself in the DB is a good idea, but where I work now, we store a lot of images in the database.

我能想到的唯一原因可能是它更安全?您不希望有人直接链接到 url 吗?但如果是这种情况,您始终可以让网站/服务器处理图像,例如 asp.net 中的处理程序,以便用户需要进行身份验证才能查看图像.我还认为从数据库中提取图像会损害性能.将图像存储在数据库中可能是好/不好的任何其他原因?

The only reason I can think of is perhaps it's more secure? You don't want someone having a direct link to an url? But if that is the case, you can always have the web site/server handle images, like handlers in asp.net so that a user needs to authenticate to view the image. I'm also thinking performance would be hurt by pulling out the images from the database. Any other reasons why it might be a good/not so good idea to store images in a database?

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

推荐答案

如果您偶尔需要检索图像,并且该图像必须在多个不同的 Web 服务器上可用.但我认为差不多就是这样.

If you on occasion need to retrieve an image and it has to be available on several different web servers. But I think that's pretty much it.

  • 如果它不必在多台服务器上可用,最好将它们放在文件系统中.
  • 如果它必须在多台服务器上可用,并且系统中实际上存在某种负载,那么您将需要某种分布式存储.

我们在这里讨论的是一种边缘情况,您可以通过利用数据库来避免给系统增加额外的复杂性.

We're talking an edge case here, where you can avoid adding an additional level of complexity to your system by leveraging the database.

除此之外,不要这样做.

Other than that, don't do it.

这篇关于要做或不做:将图像存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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