No_file_data Response In Slack File Upload

- 1 answer

I'm using node.js to try to upload a csv file via slackAPI's upload file method. The method is post. I'm unsure how to make this possible because if I use the content argument instead of the file, I get the error:

{ ok: false, error: 'invalid_array_arg' }

If I use the file aargument, I still get the error:

{ ok: false, error: 'invalid_array_arg' }

There are multiple fault points in this code and I've tried to test each one but I'm sure I'm missing some information here. Here's the uploadFile Method that I created:

function uploadFile(file){
    console.log(botToken);'', qs.stringify({token: botToken, file: file, channels: 'testing'}))
        .then(function (response) {
             var serverMessage =;
             console.log("inside file upload function");

here's how I call the method:

var file = fs.createReadStream(__dirname + '/' + csvFilePath);   // <--make sure this path is correct
    console.log(__dirname + '/' + csvFilePath);

And finally the output:

Bot has started! C:\Users\i502153\WebstormProjects\slackAPIProject/accessLogs/CSV/1548430592860output.csv* { ok: false, error: 'invalid_array_arg' } inside file upload function

What am I doing wrong and how to rectify this?




Your solution won't work because you are attempting to take a stream object (file) and stringify it into a query string, which is just going to insert the nonsense string "[object]" into the query. It won't actually stream data to Slack.

Axios, unfortunately, doesn't work in node exactly like it does in the browser, and their docs can be a little confusing.

I would suggest an approach like this (untested):

const axios = require('axios');
const FormData = require('form-data');

function uploadFile(file) {
    const form = new FormData();
    form.append('token', botToken);
    form.append('channels, 'testing');
    form.append('file', file, 'optionalfilenamehere');
    return'', form, {
        headers: form.getHeaders()
    }).then(function (response) {
        var serverMessage =;
        console.log('inside file upload function');

I adapted this code from the suggestion in ticket, there may be other helpful comments there as well if you run into issues. Good luck!

EDIT: For people reading this later, for a similar approach using request instead of axios, see related question Slack API (files.upload) using NodeJS.