I need to be able to upload a zip file to a brightsign unit and thinking of creating a rest api which I can make a put request to send the zip file.
But the problem is that all examples I find is using frameworks such as express. Is it possible to make a rest API handling a PUT requst in nodejs without using extra frameworks?
The problem is that I can only use modules that does not need a "configuration" step on the brightsign player. So I can use modules that only contain plain javascript (I hope my explanation makes sense).
You will need to listen for the PUT somehow :
const http = require('http');
const querystring = require('querystring');
const server = http.createServer().listen(3000);
server.on('request', function (req, res) {
if (req.method == 'PUT') { //PUT Only
var body = '';
req.on('data', function (data){body += data;});
req.on('end', function () {
var PUT = querystring.parse(body);
console.log(PUT);
res.writeHead(200, {'Content-Type': 'text/plain'})
res.write('\n[request received successfully]\n'); res.end();
});
}else{res.end();}
});
You can test it out using curl :
curl -X PUT -d destPath=/home/usr/images -d fileName=selfie.png -d fileData=base64string localhost:3000
In express is much simpler, comment if you need an express example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With