1 year ago

#248462

test-img

KiZaru

openDownloadStream(files[0].metadata).pipe(res) is returning FileNot found error in mongodb gridfs

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.

node.js

mongodb

gridfs

gridfs-stream

0 Answers

Your Answer

Accepted video resources