- An async Post request (Multi Form Data) with NodeJs
let formData = new FormData();
formData.append('input_file', fs.createReadStream('your file path'));
formData.append('parameter_1', 'your parameter');
const getData = async url => {
try {
const res = await axios.post(url, formData, {
// You need to use `getHeaders()` in Node.js because Axios doesn't
// automatically set the multipart form boundary in Node.
headers: formData.getHeaders()
});
const data = res.data;
console.log(data, 'Data')
} catch (error) {
console.log(error.response.data.errors, 'Error')
}
}
getData(url, formData);