Skip to content

Instantly share code, notes, and snippets.

@mcfedr
Created April 14, 2016 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcfedr/b56f25731b25121d855f9c5ef0951650 to your computer and use it in GitHub Desktop.
Save mcfedr/b56f25731b25121d855f9c5ef0951650 to your computer and use it in GitHub Desktop.
Shows how the content-length can be unknown
'use strict';
const FormData = require('form-data'),
fetch = require('node-fetch');
Promise.all([
fetch('http://httpbin.org/stream/10'),
fetch('http://httpbin.org/stream/10')
]).then(res => {
let data = new FormData();
data.append('a', res[0].body);
data.append('b', res[1].body);
data.append('c', 'something else');
data.getLengthSync = null;
return fetch('http://httpbin.org/post', {
method: 'POST',
body: data
})
.then(res => res.text())
.then(text => {
console.log(text);
});
})
.catch(err => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment