NodeJS, Axios – post file from local server to another server

The 2 oldest answers did not work for me. This, however, did the trick:

const FormData = require('form-data'); // npm install --save form-data

const form = new FormData();
form.append('file', fs.createReadStream(file.path));

const request_config = {
  headers: {
    'Authorization': `Bearer ${access_token}`,

return, form, request_config);

form.getHeaders() returns an Object with the content-type as well as the boundary.
For example:

{ "content-type": "multipart/form-data; boundary=-------------------0123456789" }

Leave a Comment