#Save images in mySQL using TypeORM

7 messages · Page 1 of 1 (latest)

earnest copper
#

Hi, I tried saving images into mySQL database using blob. I retrieve them from my frontend as File type and store them into Buffers in my backend before sending them to my database. I use FormRequest to retrieve them into backend. Do someone know a good way to store images ?

autumn wing
#

I would suggest not storing images in the database. Use a dedicated file store like the hard drive, s3, or other file storages. They'll be more efficient with the space and you won't needlessly take up database resources for things you won't query on.

In the database, save the URL of the image so that you can retrieve it

earnest copper
#

I forgot to mention that I try to develop a website, in which images can be seen by everyone, so I need to use database

autumn wing
#

Images being seen by everyone does not mean you need a database to save the images in. My statement still stands

earnest copper
#

You mean that we can store image into the server without using database ?

autumn wing
#

Yes. Or some dedicated file store. S3, Google's Firestore, Azure's Azure Files, or other storages as a service (STaaS)

sturdy geyser
#

i would like to addon you can even store images on the server it self locally
although it is recommended on a external server as it is more secure this way
see owasp guide for this
https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html#file-storage-location

it is possible to store images on DB by encoding a image into base64 string saved on DB
but for all of the better dont, dont bring such a thing upon this cursed world