存储少量图像:blob 还是 fs? [英] Storing a small number of images: blob or fs?

查看:24
本文介绍了存储少量图像:blob 还是 fs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在向我的网站添加一些功能,以便用户可以上传他们自己的个人资料图片,所以我想知道是将它们作为 BLOB 存储在数据库中,还是将它们放入文件系统中.

I'm adding some functionality to my site so that users can upload their own profile pictures, so I was wondering about whether to store them in the database as a BLOB, or put them in the file system.

我在这里发现了一个类似的问题:在数据库中存储图像:是的或不,但给出的答案更适合期望成千上万甚至数百万张图像的人,而我更关心小图像(JPEG 可能高达 150x150 像素),以及其中的一小部分:也许高达一两千.

I found a question similar to this here: Storing images in DB: Yea or Nay, but the answers given were geared more towards people expecting many many thousands or even millions of images, whereas I'm more concerned about small images (JPEGs up to maybe 150x150 pixels), and small numbers of them: perhaps up to one or two thousand.

对于这种情况,DB BLOB 与文件系统有何感受?客户端如何从数据库缓存图像与从文件系统缓存图像?

What are the feelings about DB BLOB vs Filesystem for this scenario? How do clients go with caching images from the DB vs from the filesystem?

如果将 BLOB 存储在数据库中是可行的方法 - 我是否应该了解 在哪里 存储它们?由于我认为我的大多数用户不会上传图片,我是否应该在需要时创建一个 user_pics 表来(外部)连接到常规的 users 表?

If BLOBs stored in the DB are the way to go - is there anything I should know about where to store them? Since I imagine that a majority of my users won't be uploading a picture, should I create a user_pics table to (outer) join to the regular users table when needed?

我重新打开这个问题,因为它不是你链接到的那两个的重复.这个问题特别是关于对少量图像使用 DB 或 FS 的优缺点.正如我上面所说,另一个问题针对需要存储成千上万张大图像的人.

I'm reopening this question, because it's not a duplicate of those two you linked to. This question is specifically about the pros/cons of using a DB or FS for a SMALL number of images. As I said above, the other question is targeted towards people who need to store thousands upon thousands of large images.

推荐答案

回答部分问题:

客户端如何从数据库和文件系统缓存图像?

How do clients go with caching images from the DB vs from the filesystem?

对于数据库:在您的数据库中有一个 last_modified 字段.使用 Last-Modified HTTP 标头,以便客户端的浏览器可以正确缓存.当浏览器请求图像if newer"时,一定要发送适当的响应(不记得它叫什么;一些 HTTP 请求头).

For a database: Have a last_modified field in your database. Use the Last-Modified HTTP header so the client's browser can cache properly. Be sure to send the appropriate responses when the browser requests for an image "if newer" (can't recall what it's called; some HTTP request header).

对于文件系统:做同样的事情,但使用文件的修改时间.

For a filesystem: Do the same thing, but with the file's modified time.

如果将 BLOB 存储在数据库中是可行的方法 - 我应该知道将它们存储在哪里吗?由于我认为我的大多数用户不会上传图片,我是否应该在需要时创建一个 user_pics 表来(外部)连接到常规用户表?

If BLOBs stored in the DB are the way to go - is there anything I should know about where to store them? Since I imagine that a majority of my users won't be uploading a picture, should I create a user_pics table to (outer) join to the regular users table when needed?

我会将 BLOB 和相关元数据放在自己的表中,并在它与您的用户表之间存在某种关系.这样做可以更轻松地优化数据的表存储方法,使事情更整洁,并为可扩展性留出空间(例如,一般的文件"表).

I would put the BLOB and related metadata in its own table, with some kind of relation between it and your user table. Doing this will make it easier to optimize the table storage method for your data, makes things tidier, and leaves room for expandability (e.g. a general "files" table).

这篇关于存储少量图像:blob 还是 fs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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