I have uploaded multiple image files into MongoDB using "Multer" and "multer-gridfs-storage". I want to extract these files and show them as thumbnails on the webpage. I have tried to extract these files into ReadStream and storing them into an array which i can loop.
var streams = [];
console.log(result)
for (var i = 0; i < result.length; i++) {
var gfs = Grid(conn.db);
var campground = gfs.createReadStream({
_id: result[i]._id
});
streams[i] = campground;
console.log(" " + i);
}
I want to pass these to the front end where they can be displayed, but they are not displaying. I tried running the following code in loop.
var rest
streams[0].pipe(rest)
res.writeHead(200, { 'Content-Type': 'image/jpeg' });
res.write(rest);
// res.addTrailers({ 'image/jpeg': rest });
res.end();
is not working. The following works but only displays one file
streams[i].pipe(res)
I want to pass the array of images to my ejs file. The streams[i] array is grid object and not the final images. How do i accomplish this?
Regards, Gaurav