0

I have a theoretical question, whether is it good practice to store files in the form of base64 in the database, or better save them physically on the disk and store path (indicator) to these files in the database?

I expect a theoretical explanation of the advantages and disadvantages of both practices. I must add that the size of these files is between 600kb and 3mb.

Thanks for any help

BarrySW19
  • 3,759
  • 12
  • 26
rdabrowski
  • 189
  • 1
  • 6
  • 16
  • _If_ you want to store them in the database do **not** store them as base64 encoded strings. Store them as raw bytes in a `bytea` column. –  Mar 11 '17 at 13:55
  • The real-world answer is: ask your DBAs what they would prefer you to do. If they are happy with the volumes of data you propose then put it in the database as a Clob/Blob. Don't mess about with base64 - let the DBAs set up automatic data compression. – BarrySW19 Mar 11 '17 at 13:56
  • Whether or not to do that is partly a matter of personal taste. It also depends on your requirements what you want to do with the images. Do you need transactional access to them? Go for the database. Does your web server need direct access to them? Go for the file system. Do you need to apply the same security as with other data to them? Go for the database. Do you need external programs to access them (e.g. for resizing)? Go for the filesystem. –  Mar 11 '17 at 13:57
  • Don't forget, if you put it on the filesystem it's likely you will have to worry about backups, issues with migration across servers and other stuff which your DBAs can take care of if it's in the database. – BarrySW19 Mar 11 '17 at 13:59

0 Answers0