将图像作为文件存储在文件系统中或作为BLOB数据库字段存储为二进制 [英] Storing Images In Filesystem As Files Or In BLOB Database Field As Binaries

查看:286
本文介绍了将图像作为文件存储在文件系统中或作为BLOB数据库字段存储为二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在DB中存储图片 - 是或否?


哪种方法更好?有什么优点和缺点?



在我看来,在数据库中存储图像的优点是:




  • 数据库完整性(使用外键保持所有数据库条目有效,比保存文件系统更容易,并在数据库中每次更改时进行必要的更改)

  • 更少的工作和更容易的维护(您只需要照顾一个数据存储位置 - 数据库)



缺点是: / p>


  • 在数据库服务器上加载更多



您同意上述观点吗?



目前我所做的是将小图片(如头像和缩略图)作为BLOB存储在数据库中,然后存储大图片照片或壁纸在文件系统。你认为这是一个好的方法吗?如果是,是否有一些魔法数字(文件大小),决定是否仍然有利于在数据库中存储图像?如果没有,我应该把所有的图像存储在一个地方(数据库或文件系统)?

解决方案

尝试在数据库中存储图像。数据库大小变得更大,并且对具有BLOB的表的查询变得很慢。它还增加了代码的额外复杂性,因为您必须使用非标准数据访问来检索您的映像,并必须配置为延迟加载。



存储在文件中更容易处理,您可以轻松地备份和rsync只更改那些已更改。



基本上,我从来不尝试blob任何东西,除了元数据到数据库。


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

Which approach is better? What are the advantages and disadvantages?

Advantages of storing images in database, in my opinion, are:

  • database integrity (it's easier to keep all database entries valid with foreign keys than to keep an eye on filesystem and make required changes there during each change in database)
  • less work and easier maintenance (you only need to take care of one place of data storage - database)

Disadvantage would imho be:

  • greater load on database server

Do you agree with the points above?

Currently what I do is I store small images such as avatars and thumbnails in the database as BLOBs and I store large images such as full size photos or wallpapers in the filesystem. Do you think this is a good approach? If yes, is there some magic number (file size) that decides if it's still advantageous to store an image in the database or not? If not, should I store all images just in one place (database or filesystem)?

解决方案

I've had major perf problems attempting to store images in the database. The database size gets a lot larger and queries on tables with BLOB's become a lot slower. It also adds additional complexity your code as you have to use non standard data access to retrieve your images and have to configure for lazy loading. It also significantly increases backup and replication times.

Storing in files is much easier to handle, you can easily backup and rsync only the ones that have changed.

Basically I never attempt to blob anything other than metadata into a database.

这篇关于将图像作为文件存储在文件系统中或作为BLOB数据库字段存储为二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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