Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 450
Richard Knop Avatar asked Dec 20 '25 04:12

Richard Knop


1 Answers

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.

like image 74
mythz Avatar answered Dec 22 '25 19:12

mythz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!