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

查看:227
本文介绍了存储少量图像: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.

我在这里发现了类似的问题:在DB中存储图像:Yea或Nay ,但是给出的答案更适合于期望许多数千甚至数百万图像的人,而我更关心小图像(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 vs文件系统的感觉是什么?如果客户端使用缓存来自数据库vs的图像从文件系统?

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 表(外部)加入常规

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?

编辑:我重新打开这个问题, em>不是与您链接的那两个的重复。这个问题特别是关于使用DB或FS的SMALL数量的图像的利弊。

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.

推荐答案

要回答这个问题,您的问题的部分:

To answer parts of your question:


客户端如何使用缓存来自数据库的图像vs文件系统?

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存储在DB中的方式去 - 什么我应该知道在哪里存储他们?因为我想我的大多数用户不会上传图片,我需要创建一个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天全站免登陆