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

2
  • save your file in server and insert in mongo just file name Commented Apr 29, 2017 at 20:42
  • This blog is very simple and easy to understand, it will help blog.nbostech.com/2016/10/… Commented Apr 29, 2017 at 20:54

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.