Strategy for uploading images to mongoDB Atlas with multer? Strategy for uploading images to mongoDB Atlas with multer? mongoose mongoose

Strategy for uploading images to mongoDB Atlas with multer?


If you don't want to store images locally, use MemoryStorage as Multer Storage.

var storage = multer.memoryStorage()var upload = multer({ storage: storage })

When using memory storage, the file info will contain a field called buffer that contains the entire file. So you don't have to call fs.readFileSync. You can access buffer with req.file.image.buffer and assign image data;

image.img.data = req.file.image.buffer;