Getting TypeError: Cannot read property 'name' of undefined while using form-data
7668
I am using node-fetch
and in my call I am using form-data
my code looks something like below
const fetch = require('node-fetch');
const FormData = require('form-data');
.
.
.
.
.
.
.
.
var form = new FormData();
form.append('sso_auth_token', token);
let res = await fetch(`xxxxxxxxxx`,
{
method: 'POST',
body: form
}
)
let json = await res.json();
When I run this code, I am getting following error even before the call is made
TypeError: Cannot read property 'name' of undefined
at FormData._getContentDisposition (/experimenta/foo/node_modules/form-data/lib/form_data.js:226:40)
at FormData._multiPartHeader (/experimenta/foo/node_modules/form-data/lib/form_data.js:177:33)
at FormData.append (/experimenta/foo/node_modules/form-data/lib/form_data.js:70:21)
How to fix this issue?
1 Answer
4 years ago by darc
This happens when some of the form value is undefined. I see in your code token
is a variable. Make sure that is not undefined.
form.append('sso_auth_token', (token || 'NA'));
4 years ago by Eleven