If you are developing an application with a frontend then don't save image or files to MongoDB directly, not a good idea. Use multer on nodejs, with multer you can save it to local machine like in public folder or any kind of cloud bucket as well, you need to have the file name which multer will provides you when you upload the file, just save the filename or path to database and on fetching data attach machine address with file name like, photoPath: http://ip_address/uploads/filename. And make sure enable public folder is served. If you don't wanna do that then save file in base64 format in MongoDB. but with this the problem will raise if these images has higher resolution then database size grows quickly.
#Whats the best way to upload files to mongoDB
12 messages · Page 1 of 1 (latest)
Multer is really bad, it's extremely buggy and very unmaintained. It's downright a poor choice.
Better options are things like Formidable.
Saving as base64 in Mongo is also a very bad idea. mongo has a file system called GridFS that you should use @normal scroll
If you want to store files in db
I heard about GridFs
Has been a while like more than a year using multer, never let me down, but may be I never comes across such problems. will look into Formidable.
The Devs have put it on the shelf. There are several critical issues that were never fixed, including wild memory leaks.
I also am looking into using Pechkin as a modern alternative but it's still a bit fresh
Oops I will definitely look into this.
Is gridFS a npm dependency?
No, it's a mongo feature
Okay