I scratched my head for hours trying to figure out the way to migrate after receiving the email from Slack's team of the future deprecation of file.upload
. The message is the same as https://api.slack.com/changelog/2024-04-a-better-way-to-upload-files-is-here-to-stay
Wrote this, all is successful, but no image uploaded in the channel:
#!/bin/bashlength=$(wc -c < /tmp/img.png)curl \ -H "Authorization: Bearer XXX" \ -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" \ -d "filename=charts" \ -d "length=$length" \ https://slack.com/api/files.getUploadURLExternal > /tmp/slack.jsonupload_url=$(jq -r '.upload_url' /tmp/slack.json)img_id=$(jq -r '.file_id' /tmp/slack.json)curl \ -H "Authorization: Bearer XXX" \ -d "file=@/tmp/img.png" \ $upload_urlcurl \ https://slack.com/api/files.completeUploadExternal \ -H "Authorization: Bearer XXX" \ -H "Content-Type: application/json; charset=utf-8" \ -d @/dev/stdin << EOF | jq . {"files": [ {"id": "$img_id","title": "charts", } ],"channel_id": "XYZ","initial_comment": "this is a test" } EOF
The output:
{"ok": true,"files": [ {"id": "XXXXX","created": 1727014056,"timestamp": 1727014056,"name": "charts","title": "charts","mimetype": "","filetype": "","pretty_type": "","user": "XXXXXX","user_team": "XXXXXX","editable": false,"size": 5935,"mode": "hosted","is_external": false,"external_type": "","is_public": false,"public_url_shared": false,"display_as_bot": false,"username": "","url_private": "https://files.slack.com/files-pri/XXXX/charts","url_private_download": "https://files.slack.com/files-pri/XXXX/download/charts","media_display_type": "unknown","permalink": "https://etc-onlyview.slack.com/files/XXXX/charts","permalink_public": "https://slack-files.com/XXXX","comments_count": 0,"is_starred": false,"shares": {},"channels": [],"groups": [],"ims": [],"has_more_shares": false,"has_rich_preview": false,"file_access": "visible" } ]}
If I try to open URLs in a logged in browser, I get error: There was a problem when trying to open this link We're not quite sure what went wrong. You can go back, or try looking on our Help Center if you need a hand.
Or some other URLs, I get error redirected you too many times
.
Looks like a under construction project.