-
Notifications
You must be signed in to change notification settings - Fork 671
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
Latest File Upload API showing pdf file as binary file in slack preview #2170
Comments
Hey @HarishContinube! 👋 It's exciting to hear of file uploads in Go, thanks for writing in 🤓 Uploading files using the Uploading a PDF file should be similar to other files, and I'm finding a preview is appearing with the following Node.js snippet: import fs from "fs";
import webapi from "@slack/web-api";
const filepath = "example.pdf";
const length = 25469;
const client = new webapi.WebClient(process.env.SLACK_BOT_TOKEN);
const url = await client.files.getUploadURLExternal({
filename: filepath,
length,
});
const _upload = await fetch(url.upload_url, {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}`
},
body: fs.readFileSync(filepath)
});
const _complete = await client.files.completeUploadExternal({
channel_id: process.env.SLACK_CHANNEL_ID,
files: [{ id: url.file_id }],
}); In this example, I think it's important that the It might also be possible that the If possible, can you share an example file, code snippet, or details about the file? I'm curious if large files might be the cause of this behavior! |
📝 For organizing purposes, I'm moving this issue to |
Hi @zimeg. Thanks for your response. In the last step, files.completeExternalUrl, since the process is asynchronous, I receive the next response from the bot before the file is attached. Is there a way to wait until the file is attached to Slack before proceeding with the next message in the bot?" |
@HarishContinube Of course!
You're finding an edge in the asynchronous nature with files uploads... While the file ID and Continuing with the above example, I would recommend checking the async function filesInfoMimetypeBackoff(id) {
for (let i = 1; i < 30; i *= 2) {
const info = await client.files.info({
file: id,
});
if (info.file.mimetype) {
return info;
} else {
console.log("waiting...");
}
await wait(i * 1000);
}
}
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const _info = await filesInfoMimetypeBackoff(url.file_id); When testing this and a file with length I'm hoping this is helpful for retrieving file info, but please let me know if you have other questions 🙏 ✨ |
It works fine. Thanks for your response @zimeg. |
I have integrated the latest file upload APIs in Golang. I am trying to upload a PDF file to Slack. The file is uploaded successfully but appears as a binary file in the Slack preview. However, once downloaded, it is in the correct PDF format. The filetype and mimetype values extracted from the completeExternalUrl response seem inconsistent.
Do I need to pass the filetype in any of the three API calls?
Is there any documentation for the second API call used to upload the file after the getUploadURLExternal API?
The text was updated successfully, but these errors were encountered: