0

I'm a newbie working on a first full MERN stack web app(real-estate-web-app).

I came a across a problem that needed an admin to save images to the db(using their dashboard). (server built in node/express). I solved the problem by uploading the images to db, using a buffer data type. When i retrieve the images in the frontend, i need to set src to : "data: image/png;base64,..."

SO my 2 questions are:

1). Is my approach of uploading images safe? Or should I use another approach? And is it safe to use "data: image/png;base64,..." in the src attribute? (because I noticed that this is slow)

  • Yes, of course it is "slow", especially with larger images - the load time of your HTML document will increase, and the parse time probably as well. Plus, you are effectively disabling any possibility of having these images cached, all the image data will have to load together with the document that embeds it each and every time. – CBroe Jul 22 '22 at 08:23
  • @CBroe so what approach would you recommend i take? – George Marwanqana Jul 22 '22 at 08:29
  • 1
    Why do those images "need" to be stored in the database to begin with? You'd need a good reason to not put them into the file system, where they normally belong, to begin with. But if they absolutely have to be in the database - then you can write a script that gets an ID passed, reads the data for the specific image, and outputs it to the client - and then you embed that script with `` – CBroe Jul 22 '22 at 08:36
  • @CBroe okay thanks alot bro. Now i understand where i went wrong..And why middleware like multer exists – George Marwanqana Jul 22 '22 at 12:39

0 Answers0