Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to store the file in the database or just the path of the file?

Is it better to store the file in the database or just the path of the file in question?

And especially if the volume and the file numbers are important.

like image 823
Beldi Anouar Avatar asked Jan 20 '26 08:01

Beldi Anouar


1 Answers

TL;DR

objects smaller than 256K are best stored in a database while objects larger than 1M are best stored in the filesystem

You need to decide what to do with objects between 256K and 1M.

Have a read of this Microsoft Research article - which explains this: To BLOB or Not To BLOB: Large Object Storage in a Database or a Filesystem

Notes:

  • There is actually no cut and dry solution to this, you may have reasons for doing one or the other.

    For example in a highly security critical application you may decide to store everything in the db.

  • There are many factors to think about. If you need to replicate your db, it helps to have everything in the db, because you can be sure your replicated db can serve up all the files

  • If the application is performance critical you have a good reason to store everything on the filesystem (especially if the files are large and/or you are reading/writing them a lot)

like image 59
Matt Wilko Avatar answered Jan 23 '26 02:01

Matt Wilko



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!