What’s the best way to save an image on Mongodb?

Asked

Viewed 4,055 times

2

I am developing a JS system with Node server and need to save images in Mongodb in a way that saves as much space as possible, and I am currently converting the image to String Base64 and saving as a document attribute in Collection.

However, with few photos (Full HD, 4K, 8K) soon the bank was 350MB in size, was something around 15 photos.

In addition to this method there is the one where the image is uploaded to a server folder and only the path and the image name is saved.

I want to save server space because it will be deployed on Google Cloud Platform, and I don’t want to have extra costs just because of photos.

My question is: What methods beyond the above exist to save an image in Mongodb as efficiently as possible??

Note: I have no way to post the code because I only have it on the company computer

2 answers

2


In the documentation of mongoDb, they recommend using "Gridfs" when the image changes from 16mb

  • I studied the situation more thoroughly and saw that the main practice used is to use the available storages (S3 on Amazon, Container on Azure and so on). But thanks for your help, I will research on this as well...

  • I recommend Azure (I currently use it), and if you are using c# in the backend I recommend creating webjobs.

  • I’m watching the video lessons of Balta.io on Youtube and there he also uses Azure, I’ll test and see what happens

1

I think that converting to Base64 can be an aggravating factor in your code, regardless of using gridfs, storing in binary format should already help a lot, take a look at another answer I gave, there shows how to store in binary.

image upload with media content

Browser other questions tagged

You are not signed in. Login or sign up in order to post.