You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Express路由中将图片路径传递给图片识别函数

解决方法:传递图片路径到imageReko函数

Got it, let's get this sorted out quickly. You just need to adjust your imageReko module to accept a parameter, then use that parameter instead of the hardcoded 'image2.jpg'. Here's how to do it step by step:

1. 修改image-Reko模块,接收图片路径参数

更新你的图片识别模块,让它接收一个参数来代替固定的图片路径:

// image-Reko.js
const imageReko = (imagePath) => {
  // 把原来的固定值替换成传入的参数
  const photo = imagePath; 
  // 你的图片识别逻辑代码...
};

module.exports = imageReko; // 确保函数已正确导出

2. 确认路由中调用时正确传递参数

你在路由里已经写了imageReko(req.body.img),这部分是正确的,不过可以加个小判断避免空值问题:

const imageReko = require("./image-Reko");
if(req.body.act === "post") {
  if(req.body.img){
    // 这里已正确传递路由接收到的图片路径
    imageReko(req.body.img);
    // 可选:打印日志验证参数是否正确传递
    console.log(`Passed image path: ${req.body.img}`);
  } else {
    console.warn("No image path provided in request body");
  }
  const post = new Post({
    content: req.body.content,
    firstName:req.body.firstName,
    lastName: req.body.lastName,
    img: req.body.img,
  });
  // 记得后续处理post(比如保存到数据库等)
}

这样调整后,imageReko函数里的photo变量就会自动替换成从路由传递过来的图片路径字符串,不再是固定的'image2.jpg'了。

内容的提问来源于stack exchange,提问作者Zeyad Alaa Eldin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 18:32:51