【发布时间】:2021-10-26 08:14:11
【问题描述】:
我正在尝试将数据从 react 发送到 express 服务器。
反应代码:
const imageRenderer = async () => {
const res = await axios({
method: "post",
url: "http://localhost:8080/previewRender",
data: selectedFile.filePaths,
});
console.log(res.data);
};
快递代码:
app.post("/previewRender", (req, res) => {
var fileLocation = req.body;
console.log(fileLocation);
});
但是在控制台中,文件位置显示为未定义。 selectedFile.filePaths 是对象类型。不能寄物件快递吗?
【问题讨论】:
-
我们只看到您的一小部分代码,所以很难猜到,但如果我有,我会检查您是否在 Express 应用程序中使用 body-parser 中间件
-
我没有使用任何正文解析器。
-
您需要正文解析器来读取文件。检查这个npmjs.com/package/multer。
标签: javascript node.js reactjs express