Currently, I am attempting to save an Image file that I'm sending as multipart in my MongoDB utilizing GridFS. My approach involves using multer with the memoryStorage option.
let upload = multer({ storage: multer.memoryStorage() }).single('imageFile');
app.use(upload);
When accessing the buffer inside the route, I use the following method:
let buffer: Buffer = req.file.buffer;
Thus far, saving this buffer to my MongoDB has been a challenge for me.
let writeStream = this.gfs.createWriteStream({
mode: 'w',
filename: 'Image',
content_type: 'image/png'
});
streamifier.createReadStream(buffer).pipe(writeStream);
The above snippet illustrates my attempt at saving the buffer in MongoDB.
Mongoose: fs.files.ensureIndex([ [ 'filename', 1 ] ], { w: 1 })
Mongoose: fs.chunks.ensureIndex([ [ 'files_id', 1 ], [ 'n', 1 ] ], { w: 1, unique: true })
Mongoose: fs.files.findOne({ _id: ObjectId("597089c973179c0138eef7ae") }, { w: 1, readPreference: 'primary' })
Despite the log generated by my MongoDB, nothing seems to be stored in the database.
If anyone has a solution to offer, I would greatly appreciate it. I have already attempted a troubleshooting step outlined in this source, but it did not produce the desired outcome for me.