I created the following function to load a stream file. This stream is sent to the address specified with a POST. At the destination, I have another NodeJS service that with ExpressJS "capture" this POST but I have no idea how I can save the file to the destination.
NodeJS on my PC:
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);
});
}
NodeJS on my Raspberry:
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);
});
But in the console log I get:
Received a print request from: y.y.y.y
Test data: [object Object]
How can I save this file on Rasp?