通过 Node 中间人将表单数据发送到 Java 服务器
Sending form-data to Java server through a Node middleman
我有一个应用程序使用 axios 向 节点服务器 发出请求,后者又向另一个服务器发出请求java 服务器.
从客户端调用节点服务器:
// here payload is FormData()
axios.post(url, payload).then((response) => {
return callback(null, response);
}).catch((err) => {
return callback(err, null);
});
在节点服务器中,我使用busboy:
监听请求
let rawData = '';
const busboy = new Busboy({headers: req.headers});
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
file.on('data', function (chunk) {
rawData += chunk;
});
});
现在 java 服务器也需要 FormData(就像我将它发送到节点的方式一样)。我现在如何从节点获取 FormData?我一直在谷歌上努力搜索并尝试了很多东西都是徒劳的。任何不涉及 busboy 的解决方案也会有所帮助。
中间件终于用上了busboy-body-parser which adds support for getting files from the request object as req.files. And once the file is there, I send it as form-data to the java web server using the form-data npm package. The req.files support used to be there by default in Express.js. But from 4.x, it has been deprecated。
Multer 是另一个非常好的处理 multipart/form-data.
的中间件
我有一个应用程序使用 axios 向 节点服务器 发出请求,后者又向另一个服务器发出请求java 服务器.
从客户端调用节点服务器:
// here payload is FormData()
axios.post(url, payload).then((response) => {
return callback(null, response);
}).catch((err) => {
return callback(err, null);
});
在节点服务器中,我使用busboy:
监听请求let rawData = '';
const busboy = new Busboy({headers: req.headers});
busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
file.on('data', function (chunk) {
rawData += chunk;
});
});
现在 java 服务器也需要 FormData(就像我将它发送到节点的方式一样)。我现在如何从节点获取 FormData?我一直在谷歌上努力搜索并尝试了很多东西都是徒劳的。任何不涉及 busboy 的解决方案也会有所帮助。
中间件终于用上了busboy-body-parser which adds support for getting files from the request object as req.files. And once the file is there, I send it as form-data to the java web server using the form-data npm package. The req.files support used to be there by default in Express.js. But from 4.x, it has been deprecated。
Multer 是另一个非常好的处理 multipart/form-data.
的中间件