ethanent / phin

Node HTTP client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use multipart/form-data

ASaiAnudeep opened this issue · comments

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??

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.

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)