【发布时间】:2019-07-08 18:18:27
【问题描述】:
我创建了以下函数来加载流文件。该流被发送到使用 POST 指定的地址。在目的地,我有另一个 NodeJS 服务,它使用 ExpressJS “捕获”这个 POST,但我不知道如何将文件保存到目的地。
我的 PC 上的 NodeJS:
function sendFileToRaspberry(filePath) {
var options = {
method: 'POST',
url: 'http://x.x.x.x:8080/api/print',
qs: {file: fs.createReadStream(filePath)},
headers:
{
'cache-control': 'no-cache'
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
}
我的 Raspberry 上的 NodeJS:
app.post('/api/print', function (req, res) {
ORIGINAL_IP = req.ip.replace("::ffff:", '');
console.log("Received a print request from: " + ORIGINAL_IP);
// Test history data for /api/printer API
var file = req.query.file;
console.log("Test data: " + file);
util.inspect(file);
});
但在控制台日志中我得到:
收到来自:y.y.y.y 的打印请求
测试数据:[object Object]
如何在 Rasp 上保存此文件?
【问题讨论】:
标签: javascript node.js fs requestjs