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

How to upload multiple files within single call (using files.upload)? #442

Closed
1 of 6 tasks
stojan-jovic opened this issue Jun 12, 2019 · 11 comments
Closed
1 of 6 tasks
Assignees
Labels
enhancement M-T: A feature request for new functionality Version: 1x

Comments

@stojan-jovic
Copy link

stojan-jovic commented Jun 12, 2019

Description

I'm using slackclient v1 (because I need compatibility with Python 2).
According to the files.upload documentation, when we uploading file using file field it will load file content as a multipart/form-data. However, I could not figure-out how to provide input for this parameter (through the api_call) when I want to upload multiple files at once?
Is this even possible? If yes, documentation should be updated... If no, are there any plans to add this feature?

What type of issue is this?

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion
@stojan-jovic stojan-jovic changed the title How to upload multiple files with single call (using files.upload)? How to upload multiple files within single call (using files.upload)? Jun 12, 2019
@stojan-jovic stojan-jovic changed the title How to upload multiple files within single call (using files.upload)? How to upload multiple files within single call (using files.upload)? Jun 12, 2019
@lavabyrd lavabyrd self-assigned this Jun 14, 2019
@lavabyrd lavabyrd added Priority: Low enhancement M-T: A feature request for new functionality labels Jun 14, 2019
@lavabyrd
Copy link

Unfortunately at the moment, the https://api.slack.com/methods/files.upload endpoint only allows one file to be uploaded at once, meaning you have to iterate over your file list to make these multiple uploads through one api call for each.

files = ['file1.jpg', 'file2.jpg']

for my_file in my_files:
    response = client.files_upload(
        channels='#random',
        file=my_file)
    assert response["ok"]

This is just an example and not an Async one at that but it gives you an idea of how to implement this yourself. As for whether this is something Slack has available in the future, I don't know at the moment but absolutely something I'll let our team know of your interest in.

@stojan-jovic
Copy link
Author

Understand, that's how I implemented currently, by iterating and uploading files one by one. However, I wanted to see if I can decrease pressure on Slack API.
Thank you very much for the quick response. I hope that this improvement will be on the Slack client roadmap (understand that it's low priority, but would be useful in some cases).

@c-goosen
Copy link
Contributor

Worth writing a async upload for the library that iterates over a list of files? Ive done something similar with asyncio.gather(**) before, differen't API.

@seratch
Copy link
Member

seratch commented May 20, 2020

Worth writing a async upload for the library that iterates over a list of files?

This may be a good option but we're not planning to implement it as part of this library. The straight-forward way to enable more efficient and quick ways to upload multiple files would be having another path to do that. I'll share this feedback with the teams concerned. Let me close this issue now.

@seratch seratch closed this as completed May 20, 2020
@LJMcGregor
Copy link

Any update on this, by chance? Is there any way to upload multiple files alongside one message?

@Anon-Exploiter
Copy link

Still nope :(

@yeungon
Copy link

yeungon commented Sep 14, 2021

You cannot upload more than one file when the bot is called. Here is the tip: Just upload more than one files but you do not "display" it. Then take the response from the server with the URLs of the file uploaded, and "display" with markdown. I found this method in the link below:

https://stackoverflow.com/questions/59939261/send-multiple-files-to-slack-via-api

@Anon-Exploiter
Copy link

You cannot upload more than one file when the bot is called. Here is the tip: Just upload more than one files but you do not "display" it. Then take the response from the server with the URLs of the file uploaded, and "display" with markdown. I found this method in the link below:

https://stackoverflow.com/questions/59939261/send-multiple-files-to-slack-via-api

I've already accomplished that using the same stackoverflow document you used. But there should be some official way of doing it. Or atleast the documents should have some guidance about it.

image

@zpincus
Copy link

zpincus commented Oct 18, 2022

You cannot upload more than one file when the bot is called. Here is the tip: Just upload more than one files but you do not "display" it. Then take the response from the server with the URLs of the file uploaded, and "display" with markdown. I found this method in the link below:

https://stackoverflow.com/questions/59939261/send-multiple-files-to-slack-via-api

This doesn't seem to work anymore - permalinks formatted this way do not display as file previews.

It's a pity, as there currently appears to be no way to construct a message sharing multiple images/other files unless they are public.

@seratch
Copy link
Member

seratch commented Oct 18, 2022

@zpincus Sharing permalinks still should work as long as you pick up the right URLs. But we recently released a new way to upload files onto Slack: https://github.com/slackapi/python-slack-sdk/releases/tag/v3.19.0 With the files_upload_v2 method, you can upload multiple files at a time like humans do!

@zpincus
Copy link

zpincus commented Oct 19, 2022

Thanks! The new file upload method does the trick wonderfully.

Strangely, I was never able to get any of the permalinks produced by files.upload (even via the raw web api, much less the python wrappers) to render correctly.

I could make image galleries with links to public images just fine via posting a message consisting <url1...| ><url2...| > for various urls. But the same never worked for the permalinks (or any of the URLs provided by the file info data returned by files.upload), regardless of whether I shared the images to a channel in files.upload or just uploaded them with no channel destination at first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality Version: 1x
Projects
None yet
Development

No branches or pull requests

9 participants