Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
660 views
in Technique[技术] by (71.8m points)

database - Storing images in DB vs in Folder Structure

I understand it is possible to store images in Databases as Binary large objects. But I used to see in some forum web applications that they are stored as flat files in web server machine and retrieved when needed.

What is the advantage and disadvantage in both methods?

When to go for which approach?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As usual, it depends. You need to consider the usage pattern of the images and what features your DBMS provides.

Storing images in the database:

PROS

  • If the images are to be associated with entities in your database (say, a user), the database can take care of maintaining that relationship. If, on the other hand, images aren't associated to anything in the database, you will probably not want to store them in the database.
  • If your database supports it, you will be able to process files within a transaction (I believe MS SQL 2008 supports this, I don't know if others do).
  • If you need to store multiple versions of each image (say, because they change over time), it will probably be easier to do in the database than on the file system.

CONS

  • You will be putting a lot of strain on the database.
  • Backing up your database may take a long time.

Storing images on disk:

PROS

  • Making backups is trivial
  • Inspecting images etc. just requires a file browser, no need for a database client

CONS

  • Keeping the database's view of the image collection and the actual content on the disk in sync may be non-trivial, depending on the operations you will be performing on the images.

Of course, all these concerns are particularly valid if you store large numbers of images.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...