๐Ÿ“ฆ Kong / httpsnippet

๐Ÿ“„ multipart-data.js ยท 18 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18const fs = require('fs');
const FormData = require('form-data');
const fetch = require('node-fetch');
const formData = new FormData();

formData.append('foo', fs.createReadStream('hello.txt'));
formData.append('bar', 'Bonjour le monde');

let url = 'http://mockbin.com/har';

let options = {method: 'POST'};

options.body = formData;

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error('error:' + err));