DEV Community

Discussion on: Storing Image File (binary) vs Image Base64 in Database

Collapse
 
ben profile image
Ben Halpern

Are there any performance issues with going with base64 image strings for storage in Database? Any caveats to look out for?

I feel like you could lose a few benefits. Here are some things that come to mind:

  • You're no longer making use of databases/services that specialize in storing these kinds of files (like Amazon S3)
  • You're no longer able to serve images via CDN in the same conforming way.
  • Are you planning on sending the base64 images over the wire with the HTML for future use? Depending on the size of the images that could cause problems (you probably don't want the initially request to be the size of many images when you could otherwise send them asynchronously)
  • When in doubt, conforming to a convention is probably better than doing it your own way.

I might not have your full context or could be missing something. Would love others' input to validate or invalidate my thoughts on the issue.

Collapse
 
khophi profile image
KhoPhi

Thanks Ben.

You're no longer able to serve images via CDN in the same conforming way.

True, didn't think of that. Scaling with embedded base64 could be catastrophic.

Are you planning on sending the base64 images over the wire with the HTML for future use?

Yes, send the images over the wire along with the HTML.

(you probably don't want the initially request to be the size of many images when you could otherwise send them asynchronously)

Noted.

Great points there, something for me to ponder over. Thanks.

Collapse
 
codebeautify profile image
Code Beautify

Ben pretty much nailed it, in can you are wondering how much space it would take for an image to be saved in db, just upload some small image on this tool codebeautify.net/base64/image-to-b... and count the characters :)