According to Slack's documentation is only possible to send one file per time via API. The method is this: https://api.slack.com/methods/files.upload.
Using Slack's desktop and web applications we can send multiple files at once, which is useful because the files are grouped, helping in the visualization when we have more than one image with the same context. See the example below:
Do you guys know if it's possible, via API, to send multiple files at once or somehow achieve the same results as the image above?
Thanks in advance!
In order to make the API endpoint accept multiple files, we simply need to program the action method to take an input parameter with the type of List<IFormFile> . For example, the following action method accepts a list of files representing a student's certificates. In this simple example, we only deal with form files.
You must provide either a file or content parameter. The content of the file can either be posted using an enctype of multipart/form-data (with the file parameter named file ), in the usual way that files are uploaded via the browser, or the content of the file can be sent as a POST var called content .
You can share just about any file type up to 1GB in size in Slack from your device, or add them from a file management app like Box, Dropbox, Google Drive, or OneDrive.
I've faced with the same problem. But I've tried to compose one message with several pdf files.
How I solved this task
channel
parameter(this prevents publishing) and collect permalinks from response. Please, check file object ref. https://api.slack.com/types/file. Via "files.upload" method you can upload only one file. So, you will need to invoke this method as many times as you have files to upload.<{permalink1_from_first_step}| ><{permalink2_from_first_step}| >
- Slack parse links and automatically reformat messageHere is an implementation of the procedure recommended in the other answer in python
def postMessageWithFiles(message,fileList,channel):
import slack_sdk
SLACK_TOKEN = "slackTokenHere"
client = slack_sdk.WebClient(token=SLACK_TOKEN)
for file in fileList:
upload=client.files_upload(file=file,filename=file)
message=message+"<"+upload['file']['permalink']+"| >"
outP = client.chat_postMessage(
channel=channel,
text=message
)
postMessageWithFiles(
message="Here is my message",
fileList=["1.jpg", "1-Copy1.jpg"],
channel="myFavoriteChannel",
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With