Skip to content

Responses from filesUploadV2 have files nested in the files array #1803

@zimeg

Description

@zimeg

Overview

A successful response from uploading files with the filesUploadV2 API contains a files attribute after a request like so:

const result = await web.filesUploadV2({
  token: "xoxp-example",
  channel_id: "C0123456789",
  file: "hello",
  filename: "greetings.md",
});
{
  ok: true,
  files: [ { ok: true, files: [Array], response_metadata: [Object] } ]
}

Which means accessing the ID of this file needs:

console.log(result.files[0].files[0].id);

The first [0] index is also consistent when multiple files are uploaded:

const result = await web.filesUploadV2({
  token: "xoxp-example",
  channel_id: "C0123456789",
  file_uploads: [
    {
      file: "README.md",
      filename: "README.md",
    },
    {
      content: "hello",
      filename: "greetings.md",
    },
  ],
});

console.log(result.files[0].files[0].id); // F00000README
console.log(result.files[0].files[1].id); // F00GREETINGS

Expected behaviors

This seems like unexpected behavior so wanted to check - it caught me by surprise! I expected result.files[0].id and result.files[1].id to have the file IDs 🤔

I found the following quick change removes the middle files[0] too:

return { ok: true, files: completion };

-   return { ok: true, files: completion };
+   return {
+     ok: true,
+     files: completion[0].files as FilesGetUploadURLExternalResponse[],
+     response_metadata: completion[0].response_metadata,
+   };

Also noticing a few oddities around typing differences between filesUploadV2 and files.uploadV2 but this doesn't seem so important to me if filesUploadV2 is the recommended method of file uploads (typings work well here!).

Packages:

Select all that apply:

  • @slack/web-api

Reproducible in:

The Slack SDK version

Node.js runtime version

v20.12.2

OS info

ProductName:            macOS
ProductVersion:         14.5
BuildVersion:           23F79
Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-triage-skipbugM-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documentedpkg:web-apiapplies to `@slack/web-api`semver:major

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions