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

failed to see preview after slack image download #2401

Open
rr-jino-jose opened this issue Jan 18, 2025 · 2 comments
Open

failed to see preview after slack image download #2401

rr-jino-jose opened this issue Jan 18, 2025 · 2 comments
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project

Comments

@rr-jino-jose
Copy link

rr-jino-jose commented Jan 18, 2025

Hello

hope you are all doing good.

Issue:
I have a bot where user uploads a png file and submits. I was able to download those png to my system using url_private_download key value but somehow I am not able to preview it.

I am using the following code to download it. I think its some issues with writing to stream and not sure how to handle it. I did check some old issues posted in this repo and tried few codes but nothing worked.

# typescript code
const downloadImage= (url:string ,filename:string)=>{

  const promise = new Promise((resolve,reject)=>{
      const config = {
          headers: { Authorization: `Bearer ${process.env.SLACK_BOT_TOKEN}` }
      };
      axios({
          method: "GET",
          url  : url,
          responseType: "stream",
          headers : config.headers
      }).then((result)=>{
          const writeStream = fs.createWriteStream(filename);
          result.data.on('data', (chunk: any) => {
              writeStream.write(chunk);
          });
          result.data.on('end', function () {
              writeStream.uncork();
              writeStream.close();
              writeStream.end();
              console.log("completely ending the pipe");
          });
          writeStream.on('finish', () => {
              resolve(filename);
          });
          // This is here incase any errors occur
          writeStream.on('error', function (err) {
              reject(err);
          });
      }).catch((err)=>{
          reject(err);
      });
  });
  return promise;
};

any help is appreciated for the same.

@slack/bolt version

"@slack/bolt": "^4.1.1",

App and Receiver Configuration

const app = new App({
  token: process.env.SLACK_BOT_TOKEN as string,
  appToken: process.env.SLACK_APP_TOKEN as string,
  socketMode: true,
  logLevel: LogLevel.ERROR,
});
app.command('/requests', async ({ command, ack }) => {
    try {
      // Acknowledge command request
      await ack();
      // Open a modal for ticket submission
      await app.client.views.open({
        trigger_id: command.trigger_id,
        view: createIssueModal(command.channel_id),
        });
    } catch (error) {
    console.error(error);
  }
});

Node.js runtime version

 node --version                                                                                                                                                   
v18.19.0

Expected result:

after download I can preview the image

@rr-jino-jose rr-jino-jose changed the title (Set a clear title describing your question) failed to see preview after slack image download Jan 18, 2025
@seratch seratch added question M-T: User needs support to use the project needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info and removed untriaged labels Jan 20, 2025
@seratch
Copy link
Member

seratch commented Jan 20, 2025

Hi @rr-jino-jose, thanks for asking the question.

somehow I am not able to preview it

What do you mean by "failt to preview it"? Does it mean the downloaded file data is broken? Are you looking for a way to display the file content in a message or on a modal?

If the file your code downloads is not valid, my past comment at #1711 (comment) may be helpful. I don't think the operation could be that complicated.

@rr-jino-jose
Copy link
Author

rr-jino-jose commented Jan 24, 2025

Hey @seratch. Thanks for the reply.

Yes the downloaded file data is broken. I did tried your code, it downloads the file but can't open it .. Initially I thought it might be due to some missing permissions but its not. (I gave all the permissions for file:* in Bot Token Scopes and User Token Scopes)

After writing it into a file, when I open it gives me the error (in screenshot). Also I tried via terminal:

wget --header="Authorization: Bearer ${SLACK_BOT_TOKEN}" "https://files.slack.com/files-pri/<org hash code>/download/screenshot_2025-01-10_at_10.21.51___am__3_.png"

it downloads but can't open it via any application. So have no idea what else I might be missing.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs info An issue that is claimed to be a bug and hasn't been reproduced, or otherwise needs more info question M-T: User needs support to use the project
Projects
None yet
Development

No branches or pull requests

2 participants