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

[QUERY] How to use files.upload to upload a binary file #94

Open
spencerwilson opened this issue Mar 5, 2024 · 3 comments
Open

[QUERY] How to use files.upload to upload a binary file #94

spencerwilson opened this issue Mar 5, 2024 · 3 comments
Labels
question Further information is requested

Comments

@spencerwilson
Copy link

spencerwilson commented Mar 5, 2024

Question

How does one use files.upload? I tried

import { Readable } from "node:stream";

// ...

      // This is a `ReadableStream<Uint8Array>`...
      const audio = (await fetch("https://upload.wikimedia.org/wikipedia/commons/7/71/George_Gershwin_2.ogg")).body!;

      const response = await client.files.upload({
        channels: "<channel ID>",
        title: "Title",
        initial_comment: "Comment",
        // ...which I adapt into a Node.js `Readable` here
        file: Readable.from(audio),
        filename: "audio.ogg",
        filetype: "ogg",
      });

With this code, the API response is {"ok":false,"error":"no_file_data"}. I was expecting this to work since the files.upload JavaScript sample code, whose docs do similar, refer to something like the above as the legacy way to upload files. My use case is simple so I think I'm ok with a legacy way, as long as it works. Thanks!

Context

Environment

"deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.5.0/",
"deno-slack-api/": "https://deno.land/x/deno_slack_api@2.1.2/",

deno 1.40.5 (release, aarch64-apple-darwin)
v8 12.1.285.27
typescript 5.3.3

ProductName: macOS
ProductVersion: 14.2.1
BuildVersion: 23C71
Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000

Requirements

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

@seratch seratch added the question Further information is requested label Mar 5, 2024
@seratch
Copy link
Member

seratch commented Mar 5, 2024

Hi @spencerwilson, thanks for asking the question! Our team is working on the files.upload v2 method addition in this PR: #90 but it seems the changes may need some time until its release.

As a short-term solution, checking my code example mentioned at #89 may be helpful for you. The code uploads a text file but you should be able to upload audio file by adjusting some parts of it.

@spencerwilson
Copy link
Author

spencerwilson commented Mar 5, 2024

Thanks very much @seratch , I'll give that a try! Here's some misc other context that Slack folks might want to know:

@spencerwilson spencerwilson changed the title [QUERY] How to use files.upload [QUERY] How to use files.upload to upload a binary file Mar 5, 2024
@ChuckJonas
Copy link

I'm here for the same reasons :(

The client (injected from the deno function) does not seem to have a method called slackApi.files.getUploadURLExternal.

@spencerwilson how did you end up implementing this? Did you just use the token to call the endpoint with fetch?

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

No branches or pull requests

3 participants