Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'name' of undefined #2662

Closed
jasonxia23 opened this issue May 16, 2017 · 3 comments
Closed

TypeError: Cannot read property 'name' of undefined #2662

jasonxia23 opened this issue May 16, 2017 · 3 comments

Comments

@jasonxia23
Copy link

Summary

TypeError: Cannot read property 'name' of undefined

Simplest Example to Reproduce

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'
            }
        }
    }
} 

Current Behavior

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)

Your Environment

software version
request 2.81.0, 2.78.0
node 6.10.1
npm 3.10.10
Operating System MacOS
@matteodisabatino
Copy link

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.

@ca0v
Copy link

ca0v commented Dec 8, 2017

Remove the "(ex)" and tsc exits with this error.

try {
} catch (ex) {
console.warn(``);
}

@jsdevtom
Copy link

Expanding on @matteodisabatino's comment, any property that is == undefined inside formData will cause this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants