我已经制作了一个功能,可以在Node.js的Express服务器上将图像旋转90度。它在第一次调用时有效,但是在第二次调用时无效。如果我重新启动服务器,它将再次工作一次,因此,如果我重新启动服务器3次,则可以一直旋转图像。Product.findById是一个猫鼬查询,用于查找从前端请求中指定的图像ID的图像名称。在第一次和第二次尝试中,第7行的console.log返回正确的工厂路径/名称,并且不会引发任何错误。响应状态也是200次“图像旋转”router.patch("/rotate/:image", (req, res, next) => { let image = "" Product.findById(req.params.image) .exec() .then(result => { image = './uploads/resized/'+result.image console.log("image", image) sharp(image) .rotate(90) .withMetadata() .toBuffer(function(err, buffer) { if(err) throw err fs.writeFile(image, buffer, function() { res.status(200).json("image rotated") }); }) }) .catch(err => {res.status(400).json("invalid img id") console.log(err)}) })预期的输出是在每个http请求上将图像旋转90度,但实际输出仅是在第一个http请求上将图像旋转90度。
添加回答
举报
0/150
提交
取消