[英]Unable to send data from react to express server
I am trying to send data from react to express server.我正在尝试将数据从反应发送到快递服务器。
React code:反应代码:
const imageRenderer = async () => {
const res = await axios({
method: "post",
url: "http://localhost:8080/previewRender",
data: selectedFile.filePaths,
});
console.log(res.data);
}; };
Express code:快递代码:
app.post("/previewRender", (req, res) => {
var fileLocation = req.body;
console.log(fileLocation);
});
However in console the filelocation is shown as undefined.但是在控制台中,文件位置显示为未定义。 selectedFile.filePaths is of type object.
selectedFile.filePaths 是对象类型。 Can't I send object to express?
不能发对象快递吗?
Add this in app.js (app.js)
or your root file of the app to post req将此添加到 app.js
(app.js)
或应用程序的根文件中以发布请求
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
Put this middleware in app.js
above your routes...将此中间件放在
app.js
您的路线上方...
你在你的 app.js 中使用了app.use(express.json())
吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.