Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make http put request with zip file in nodejs

I want to make a http PUT request with zip file in binary to a web api and get response with http status code.

How to read the file and PUT it with binary ?

Thank you for your help!!

like image 485
Kevingo Tsai Avatar asked Oct 15 '25 18:10

Kevingo Tsai


1 Answers

You can start with this:

var http = require('http');
var fs   = require('fs');

var req = http.request({
  hostname : HOSTNAME,
  port     : PORT,
  path     : UPLOAD_PATH,
  method   : 'PUT',
});

fs.createReadStream('somefile.zip').pipe(req);

You may need to perform some other actions, like proper error handling, setting Content-Type headers, etc.

like image 114
robertklep Avatar answered Oct 18 '25 10:10

robertklep