Search code examples
slackslack-api

WebClient files.upload fails with cannot read property 'name' of undefined


When trying to upload a file using the files.upload API on my server I encounter the following error when the file I'm uploading is being converted to multi-part form-data:

TypeError: Cannot read property 'name' of undefined 
    at FormData._getContentDisposition (/app/node_modules/form-data/lib/form_data.js:226:40) 
    at FormData._multiPartHeader (/app/node_modules/form-data/lib/form_data.js:177:33) 
    at FormData.append (/app/node_modules/form-data/lib/form_data.js:70:21) 
    at flattened.reduce (/app/node_modules/@slack/client/dist/WebClient.js:459:26) 
    at Array.reduce (<anonymous>) 
    at WebClient.serializeApiCallOptions (/app/node_modules/@slack/client/dist/WebClient.js:438:30) 
    at WebClient.<anonymous> (/app/node_modules/@slack/client/dist/WebClient.js:342:38) 
    at Generator.next (<anonymous>) 
    at /app/node_modules/@slack/client/dist/WebClient.js:7:71
    at new Promise (<anonymous>)

It works for me locally, but on my server the same code gives the above response. Does anyone know what can cause this?


Solution

  • This seemingly unrelated error message occurs if the token that the WebClient is initialised with is undefined.

    I have raised an issue in Slack's Github to track this.