1

This is my route file where I stream the image data to the browser.

router.get('/image/:id', auth, (req, res) => {
const metadata = req.params.id;

gfs.find({ metadata: metadata }).toArray((err, files) => {
if (!files || files.length === 0)
  return res.status(404).send('Files does not exist.');

if (err) {
  return res.status(404).send('Files not found');
}

 gfs.openDownloadStream(files[0].metadata).pipe(res);
});
});

if i console.log(files) then i get all of the image data i want but when i try to stream using the metadata where the id of the user who has uploaded is stored I get a file not found error. I don't know if the openDownloadStrem requires id only.

Kirollos Mallak
  • 359
  • 4
  • 12
KiZaru
  • 57
  • 1
  • 7

0 Answers0