I'd like to send an HTTP post request using the scoped-http-client
, like this:
client('http://url-to-post-to.com/').post({filedata: <data from stream>})
How would I pass in the data of a node stream?
I'd like to send an HTTP post request using the scoped-http-client
, like this:
client('http://url-to-post-to.com/').post({filedata: <data from stream>})
How would I pass in the data of a node stream?
From their documentation, you can get access to the http.ClientRequest which is a writable stream. From there, you can just pipe the file data to the request. For example, if you were to send JSON file data:
var fs = require("fs"),
scopedClient = require("scoped-http-client");
var file = fs.createReadStream("./test.json");
var client = scopedClient.create("http://url-to-post-to.com/").header("Content-Type", "application/json");
client.post(function(err, req) {
file.pipe(req);
});