8

I've been fighting slack's files.upload API. Even if I insist the file should be any kind of format that isn't plain text, example:

    request.post({
      url: 'https://slack.com/api/files.upload',
      formData: {
        token: bot.config.token,
        channels: message.channel,
        file: fs.createReadStream(realLocalPath),
        filetype: 'zip',
        mode: 'hosted'
      },
    }, function (err, response) {
        console.log(JSON.parse(response.body));
    });

It seems to insist on making it plaintext with preview:

     mimetype: 'text/plain',
     filetype: 'text',
     pretty_type: 'Plain Text',
     ...
     mode: 'snippet'

That's from the API response's file property. Does anyone know how I can override this?

I want my file to be a downloadable one. No snippet, no preview, just a downloadable file.

Tiago
  • 1,984
  • 1
  • 21
  • 43
  • Did you ever resolve this? It looks like if the attachment is over 1MB it won't show the preview. But I'd like to always force no preview. – Constantino May 19 '20 at 20:23
  • @Constantino This is what I've opted for in the end, though I honestly can't remember if I resolved the initial problem: https://github.com/tiagosiebler/Jarvis/blob/master/skills/corpLinkHandler.js#L29 Hope it helps! (and sorry about the somewhat dirty old code) – Tiago May 20 '20 at 14:26

0 Answers0