ethanent / phin

Node HTTP client
MIT License
576 stars 33 forks source link

How to use multipart/form-data #47

Closed ASaiAnudeep closed 4 years ago

ASaiAnudeep commented 4 years ago

Hi,

I am trying to make a request with multipart/form-data. Is it possible to send such requests in phin.

Can I use form-data in phin??

ThatTonybo commented 4 years ago

As far as I'm aware either parse a JSON object in the request's { data } field, or you could try using form-data. Just set the request header to indicate so.

ASaiAnudeep commented 4 years ago

I was able to use form-data with the following code:

const options = {};
const form = new FormData();
form.append('my_file', fs.readFileSync(path), { contentType: 'application/xml', filename: 'jUnit.xml' });
options.data = form.getBuffer();
options.headers = form.getHeaders();
phin(options)