problem description
word files accessed by mongodb need to be displayed in the browser, but the browser is not good at displaying office files, so the current solution is to read word, through gridfs-stream in the background and then convert it to pdf
.the environmental background of the problems and what methods you have tried
node.js
related codes
const downloadFile = function (isPicture, req, res, next) {
req.checkParams("id", "id").isMongoId();
let id = req.params.id;
let errors = req.validationErrors();
if (errors) {
return res.error(errors[0].msg);
}
Services.Gridfs.getOne(id).then(function (file) {
if (file) {
res.header("Content-Type", file.contentType);
if (!isPicture) {
setContentDispositionHeader(req, res, file.filename);
}
let gfs = utils.Gridfs.getGridfs();
var readstream = gfs.createReadStream({
_id: id
});
readstream.on("error", function (error) {
next(error);
});
readstream.pipe(res);
} else {
return res.error("", 404);
}
}).catch(err=>next(err));
};