TypeError: Cannot read property 'name' of undefined
request.post({
url: '/cdn/upload',
formData: {
// Pass a simple key-value pair
my_field: 'my_value',
// Pass data via Buffers
my_buffer: new Buffer([1, 2, 3]),
// Pass data via Streams
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
// Pass multiple values /w an Array
attachments: [
fs.createReadStream(__dirname + '/attachment1.jpg'),
fs.createReadStream(__dirname + '/attachment2.jpg')
],
// Pass optional meta-data with an 'options' object with style: {value: DATA, options: OPTIONS}
// Use case: for some types of streams, you'll need to provide "file"-related information manually.
// See the `form-data` README for more information about options: https://github.com/form-data/form-data
custom_file: {
value: fs.createReadStream('/dev/urandom'),
options: {
filename: 'topsecret.jpg',
contentType: 'image/jpeg'
}
}
}
}
TypeError: Cannot read property 'name' of undefined
at FormData._getContentDisposition (/path-to-project/node_modules/request/node_modules/form-data/lib/form_data.js:217:43)
at FormData._multiPartHeader (/path-to-project/node_modules/request/node_modules/form-data/lib/form_data.js:171:33)
at FormData.append (/path-to-project/node_modules/request/node_modules/form-data/lib/form_data.js:64:21)
at appendFormValue (/path-to-project/node_modules/request/request.js:327:21)
at Request.init (/path-to-project/node_modules/request/request.js:338:11)
at new Request (/path-to-project/node_modules/request/request.js:128:8)
at request (/path-to-project/node_modules/request/index.js:54:10)
at Function.post (/path-to-project/node_modules/request/index.js:62:12)
at /path-to-project/publish.js:30:21
at FSReqWrap.oncomplete (fs.js:123:15)
| software | version
| ---------------- | -------
| request | 2.81.0, 2.78.0
| node | 6.10.1
| npm | 3.10.10
| Operating System | MacOS
This happened me too with version 2.81.0; was my own fault because I was passing an undefined value in the formData. So, considering the code you've written, the problem may stand on the path of files, print them before call the request and check if they are right.
Remove the "(ex)" and tsc exits with this error.
try {
} catch (ex) {
console.warn(``);
}
Expanding on @matteodisabatino's comment, _any_ property that is == undefined
inside formData
will cause this issue.
Most helpful comment
This happened me too with version 2.81.0; was my own fault because I was passing an undefined value in the formData. So, considering the code you've written, the problem may stand on the path of files, print them before call the request and check if they are right.