将图像存储在数据库或文件系统中

发布于 2024-10-09 11:58:56 字数 299 浏览 5 评论 0原文

可能的重复:
在数据库中存储图像 - 是或否?

是否更快、更多在文件系统中存储图像可靠还是应该将它们存储在数据库中?

假设图像不大于 200 MB。目标是快速、可靠的访问。

一般来说,人们如何决定将文件(例如图像、PDF)存储在文件系统中还是数据库中?

Possible Duplicate:
Storing Images in DB - Yea or Nay?

Is it faster and more reliable to store images in the file system or should I store them in a database?

Let's say the images will be no larger than 200 MB. The objective is fast, reliable access.

In general, how do people decide between storing files (e.g., images, PDFs) in the file system or in the database?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

痴梦一场 2024-10-16 11:58:56

个人观点:我总是将图像存储在文件系统上,并且仅在数据库中存储文件路径。在许多情况下,数据库存储在快速(读取:昂贵的存储、15k RPM 或 SSD 驱动器)存储上。图像或其他文件通常可以存储在速度较慢(即:更便宜、更大的驱动器、7.2k RPM 驱动器)的存储上。

我发现这是最好的,因为它允许数据库保持较小的大小。一般来说,数据库可以很好地存储“数据”。他们可以快速搜索和检索少量数据。文件系统可以很好地存储“文件”,它们经过优化可以快速查找和检索更大的数据位。

显然,这两种方法都需要权衡,并且不会存在一刀切的方法。但是,在某些用例中,如果图像都非常小,并且您预计图像不会很多,并且您的数据库与文件共享位于同一存储介质上,则将图像存储在数据库中可能是一件好事,那么将图像直接放入数据库可能是有意义的。

附带说明一下,SQL Server 2008R2 有一个 FileStream 字段类型,它可以提供两全其美的功能,我还没有使用它,所以我不能说它的工作效果如何。

Personal opinion: I ALWAYS store images on the file system, and only store a filepath in the database. In many situations, databases are stored on fast (read: expensive storage, 15k RPM or SSD drives) storage. Images or other files, typically can be stored on slower (read: cheaper, larger drives, 7.2k RPM drives) storage.

I find this to be the best, since it allows for the database to remain small in size. In general, databases store "data" well. They can search and retrieve small bits of data fast. File Systems store "files" well, they are optimized to find and retrieve larger bits of data fast.

Obviously there are tradeoffs to both approaches, and there isn't going to be a one-size fits all; however, there may be some use cases where storing images in the database is a good thing, if they are all quite small, and you don't anticipate very many of them, and your database is on the same storage medium as your file share, then it probably makes sense to drop the images directly into the database.

As a side note, SQL Server 2008R2 has a FileStream field type, which can provide the best of both worlds, I have not used it yet, so I can't speak to how well it works.

望她远 2024-10-16 11:58:56

如果您需要以下功能,请将文件/图像存储在数据库中:

  • 访问控制
  • 版本
  • 控制 签入/签出
  • 基于元数据的搜索

这一直是 SharePoint 等主要 CMS 的设计。

但是,如果您的内容更加静态并且不会随时间变化,您可以使用文件系统并在 Web 服务器上启用优化/缓存。

Store files/images in the database if you require following:

  • Access Control
  • Versioning
  • Checkin/Check out
  • Searching based on metadata

That has been the design of major CMS like SharePoint has been.

However, if your content is much more static and not going to change over time , you can go with files ystem and enable optimizations/cache on the web server.

盗琴音 2024-10-16 11:58:56

使用数据库方法,您只需连接到一件事。如果您的用户是分布式的,那可能会更简单。请注意,如果图像访问不太频繁,效率问题可能并不重要。

With the database approach, you only have one thing to connect to. If your users are distributed, that might be simpler. Note that if the images are not accessed too frequently, the efficiency issues might not matter.

别理我 2024-10-16 11:58:56

首先你必须知道在数据库中,你不能存储大于我认为8MB的文件,所以我认为最好将文件存储在系统中,并将小图像存储在数据库中

First of all you must know that in databases, you can't store files bigger than i think 8 mb, leavinig that, so i think is better to store files in the system, and small images in the database

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文