3
module.exports.validateUser = function (req, res) {
  User.find({ 'username': req.body.username, 'password': req.body.password }, function (err, result) {
    if (result.length) {
        var gridfs = req.app.get('gridfs');
        var readstream = gridfs.createReadStream({
            _id: result[0]._doc.picture
        });
        req.on('error', function (err) {
            res.send(500, err);
        });
        readstream.on('error', function (err) {
            res.send(500, err);
        });

        // Just sends the file
        //readstream.pipe(res);
        res.send('This is incedible');
    } else {
        res.send(false);
    }
  });
};

Just after the user is validated I am getting the file associated with it. Further I want to send some data along with the fine in response. I've used multer and gridfs-stream. Is this achievable. If not, then does something looks fishy in this approach?

Shreyas
  • 1,927
  • 17
  • 34
  • Hi, sorry your question has not been answered yet. If you still need the answer, I need to ask: Can the extra data be stored in the file metadata when you save the file, or is that data generated later? – MForMarlon Jul 16 '19 at 21:10

0 Answers0