在DB vs中将图像存储在文件夹结构中 [英] Storing images in DB vs in Folder Structure

查看:147
本文介绍了在DB vs中将图像存储在文件夹结构中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我理解可以将数据库中的图像存储为二进制大对象。但我曾经在一些论坛的Web应用程序中看到他们作为平面文件存储在Web服务器机器中,并在需要时检索。



这两种方法的优点和缺点



什么时候采用哪种方法?

解决方案

, 这取决于。您需要考虑图片的使用模式和DBMS提供的功能。



在数据库中存储图片



PROS




  • 如果图像与数据库中的实体相关联),数据库可以负责维护这种关系。另一方面,如果图像未与数据库中的任何内容相关联,则可能不想将它们存储在数据库中。

  • 如果数据库支持它,能够处理一个事务中的文件(我相信MS SQL 2008支持这一点,我不知道如果别人做)。

  • 如果你需要存储每个图像的多个版本因为它们随时间变化),在数据库中比在文件系统上更容易做。



CONS




  • 您将对数据库造成很大的压力。

  • 备份数据库可能需要很长时间
  • p> PROS




    • 进行备份很简单

    • 检查图片等只需要一个文件浏览器,不需要数据库客户端



    CONS




    • 根据您将对图像执行的操作,保持数据库对映像集合和磁盘上实际内容同步的视图可能并不重要。



    当然,如果你存储大量的图像,所有这些问题是特别有效的。


    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?

    解决方案

    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.

    这篇关于在DB vs中将图像存储在文件夹结构中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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