Saving images: files or blobs?

Viewed 55418

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 - Yea or Nay?

11 Answers

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

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

Related