bumblebeen
bumblebeen

Reputation: 692

Send http request using octet/stream via node.js

Currently my usecase is my node.js Server Server A needs to create a CSV file then send that CSV to another Server Server B which only accepts application/octet-stream.

Currently I'm manually CURLing the csv to upload it to Server B.

curl -H "Content-Type:application/octet-stream" 
    -X PUT https://someexample.com/url/what/not 
    --upload-file newlyCreated.csv

But I need to automate the curl above and wanted to use node.js since Server A is built in node.js. My instincts leads me to use streams but I can't seem to make it work.

fs.createReadStream('/path/to/csv').pipe(httpRequestToServerB)

Then respond to client and send a JSON that it is successful

Upvotes: 1

Views: 2660

Answers (1)

bumblebeen
bumblebeen

Reputation: 692

Currently, I've found the answer to my question using request NPM module:

fs.createReadStream('/path/to/csv').pipe(request.post('url').on('end', (done) => {
  console.log('Upload Done')
}));

Hope this helps

Upvotes: 1

Related Questions