Storing Images In Filesystem As Files Or In BLOB Database Field As Binaries [duplicate]

China☆狼群 提交于 2020-05-08 16:06:09

问题


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)?


回答1:


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.




回答2:


IMHO binary data has no place to be in a database. (of course there can be exception to this rule)



来源:https://stackoverflow.com/questions/2262646/storing-images-in-filesystem-as-files-or-in-blob-database-field-as-binaries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!