node.js - 如何在显示图像时调整使用 multer-gridfs-storage 存储的图像大小
问题描述
这些是以下路线的变量
const GridFsStorage = require("multer-gridfs-storage");
const Grid = require("gridfs-stream");
var conn = mongoose.createConnection(db, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
let gfs;
conn.once("open", () => {
gfs = Grid(conn.db, mongoose.mongo);
gfs.collection("uploads");
});
这是我目前正在阅读文件的方式
router.get("/image/:filename", (req, res) => {
gfs.files.findOne({ filename: req.params.filename }, (err, file) => {
if (!file || file.length === 0) {
return res.status(404).json({
err: "No file exist",
});
}
//check if it's a jpeg
if (
file.contentType === "image/jpeg" ||
file.contentType === "img/png" ||
file.contentType === "image/png"
) {
//read output to browser
const readstream = gfs.createReadStream(file.filename);
readstream.pipe(res);
} else {
res.status(404).json({
err: "Not an image",
});
}
});
});
如果可能的话,我如何在使用任何外部模块在上述路线中显示图像时调整图像大小,或者其他解决方案也是可以接受的
解决方案
推荐阅读
- dvc - 数据版本控制 (dvc) 无法推送到远程存储,因为查询缓存
- c++ - 为什么 shared_ptr 在函数中返回时没有隐式转换为布尔值?
- python - 如何在多重赋值语句中添加换行符?
- reactjs - 为不同的路由使用不同的模板反应路由器 v. 5
- angular - 反应形式外的提交按钮不起作用
- data-structures - 某些 ETS 表类型之间有什么区别?
- android - Android 4.4 失去 wifi 并在 http 请求突发时立即重新连接
- javascript - 尝试使用 Dreamweaver 在 html 页面上实现 javascript,(鼠标跟踪器)
- c# - 如何在datagirdview c#中显示完整的xml文件
- python - 如何并排放置 django 表单字段