Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File save on File System VS In Database

I'm designing a servlet(or action in Struts2) for file(images, documents, etc...) download. But I'm wondering which is better approach to keep files on File system and in database just keep the path to the file OR to keep the files in the database like BLOBs. I know that when I do query on database where is blobs is slower, but if I keep in database It would me it easier to backup the data and guarantee consistency. Any suggestions?

like image 872
Zemzela Avatar asked Dec 12 '25 23:12

Zemzela


2 Answers

I never used a BLOB. E.g. I just store user uploaded photos normally in directories. I don't see much reason for using a BLOB for storing files. You say it could be easier to backup - on the contrary, that could become very problematic, at least in our case as we have many GB of photos, but the database must be kept rather small in order to be able to backup it often and with PHPMyAdmin.

like image 174
Tomas Avatar answered Dec 14 '25 20:12

Tomas


I think that you gave a good solution: store files themselves in file system an references in DB. Storing media files in relational DB does not give you serious advantages but increases DB volume and decreases performance (as mentioned by @Amir Raminfar).

Probably good approach these days is to store files in key-value-store or so called NoSql database, e.g. Casandra or Redis.

like image 24
AlexR Avatar answered Dec 14 '25 18:12

AlexR