Saving images: files or blobs?

后端 未结 11 2191
暖寄归人
暖寄归人 2020-11-30 07:59

When you save your images (supose you have lots of them) do you store then as blobs in your Database, or as files? Why?

Duplicate of: Storing Images in DB -

相关标签:
11条回答
  • 2020-11-30 08:24

    I would suggest to go for File systems. First, let's discuss why not Blob? So to answer that, we need to think what advantages DB provides us over File system?

    1. Mutability: We can modify the data once stored. Not Applicable in case of images. Images are just a series of 1s and 0s. Whenever we changes an image, it wouldn't be a matter of few 1s and 0s altered and hence, modifying the same image content doesn't make sense. It's better to delete the old one, and store new.
    2. Indexing: We can create indexes for faster searching. But it doesn't apply on images as images are just 1s and 0s and we can't index that.

    Then why File systems?

    1. Faster access: If we are storing images in Blob inside our DB, then a query to fetch the complete record (select *) will result in a very poor performance of the query as a lots and lots of data will be going to and from the DB. Instead if we just store the URL of images in DB and store images in a distributed file system (DFS), it will be much faster.
    2. Size limit: If DBs are storing images, a lot and lot of images then it might face performance issues and also, reach its memory limit (few DBs do have it).
    0 讨论(0)
  • 2020-11-30 08:25

    Using file System is better as the basic feature you would be provided with while storing images as a blob would be 1. mutability which is not needed for an image as we won't be changing the binary data of images, we will be removing images as whole only 2. Indexed searching :which is not needed for image as the content of images can't be indexed and indexed searching searches the content of the BLOB.

    Using file system is beneficial here because 1. its cheaper 2. Using CDN for fast access

    hence one way forward could be to store the images as a file and provide its path in database

    0 讨论(0)
  • 2020-11-30 08:26

    I usually go with storing them as files, and store the path in the database. To me, it's a much easier and more natural approach than pushing them into the database as blobs.

    One argument for storing them in the database: much easier to do full backups, but that depends on your needs. If you need to be able to easily take full snapshots of your database (including the images), then storing them as blobs in the database is probably the way to go. Otherwise you have to pair your database backup with a file backup, and somehow try to associate the two, so that if you have to do a restore, you know which pair to restore.

    0 讨论(0)
  • 2020-11-30 08:26

    It depends on the size of the image.

    Microsoft Research has an interesting document on the subject

    0 讨论(0)
  • 2020-11-30 08:27

    Blobs can be heavy on the db/scripts, why not just store paths. The only reason we've ever used blobs is if it needs to be merge replicated or super tight security for assets (as in cant pull image unless logged in or something)

    0 讨论(0)
提交回复
热议问题