Skip to content

Instantly share code, notes, and snippets.

@andrit
Created July 25, 2018 15:21
Show Gist options
  • Save andrit/1947f3df3fd442b00cc2076ded09db6c to your computer and use it in GitHub Desktop.
Save andrit/1947f3df3fd442b00cc2076ded09db6c to your computer and use it in GitHub Desktop.
const axios = require('axios');
const FormData = require('form-data');

const form = new FormData();
// Second argument  can take Buffer or Stream (lazily read during the request) too.
// Third argument is filename if you want to simulate a file upload. Otherwise omit.
form.append('field', 'a,b,c', 'blah.csv');
axios.post('http://example.org/endpoint', form, {
  headers: form.getHeaders(),
}).then(result => {
  // Handle result…
  console.log(result.data);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment