0

i am new to the MEAN steak and i am tryingto upload a file from my computer to my project and in the mongoDb databse. I don't need to use gridFs from mongo because my images are much smaller. Can someone give me an example, or tell me what's the logic.

Tannk you, Adrian

Adrian
  • 67
  • 1
  • 14
  • save your file in server and insert in mongo just file name – bxN5 Apr 29 '17 at 20:42
  • This blog is very simple and easy to understand, it will help http://blog.nbostech.com/2016/10/store-and-read-image-file-in-mongodb-using-nodejsexpressmongoose/ – Don Apr 29 '17 at 20:54

1 Answers1

1

It is not suggested to store images in a database, because you have performance issues when pulling long strings... The suggested solution is something like s3 from Amazon which stores the actual files, but since your question is how to store an image in mongodb here is what you need to know.

This is stored as a dataUrl aka a freakishly long string not entirely ideal for sending in Json responses. You will need to convert the image to a base64 representation of the image and here is a link to an explanation of your stored string format.

How to implement -toDataURL() function in node.js server?

Here is a link on converting an image to base64 using node.js

NodeJS base64 image encoding/decoding not quite working

If this answers your question please mark this as the best answer

Community
  • 1
  • 1