What is the best way to save an image in MongoDB?

1

I'm 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'm currently converting the image to Base64 String and saving as an attribute of a document in the collection.

But with a few photos (Full HD, 4K, 8K), the bank was 350MB in size, it was about 15 photos.

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

I want to save server space because it will be deployed to the Google Cloud Platform, and I do not want to have extra costs just because of photos.

My question is: What methods other than those mentioned above exist to save an image in MongoDB as efficiently as possible ??

Note: I can not post the code because I have it only on the company computer

    
asked by anonymous 08.10.2017 / 23:50

2 answers

2

In mongoDb documentation, they recommend using "GridFs" when the image goes over 16mb

    
09.10.2017 / 14:16
1

I think converting to base64 can be an aggravating factor in your code, regardless of whether to use gridfs, store in binary format should already help a lot, take a look at another response I gave, there shows how to save in binary.

upload image with meteor

    
27.12.2017 / 14:41