由于 slack file.upload 将被贬值,我打算让新的方法发挥作用。
第一个的工作原理是:
curl -s -F [email protected] -F filename=test.txt -F token=xoxp-token -F length=50123 https://slack.com/api/files.getUploadURLExternal
并返回
{"ok":true,"upload_url":"https:\/\/files.slack.com\/upload\/v1\/CwABAAAAXAoAAVnX....","file_id":"F07XXQ9XXXX"}
第二个要求是:
curl -X POST \ -H "Authorization: Bearer xoxp-token" \
-H "Content-Type: application/json" \
-d '{
"files": [{"id":"F07XXXXXX", "title":"Slack API updates Testing"}],
"channel_id": "C06EXXXXX"
}' \
https://slack.com/api/files.completeUploadExternal
对于第二个请求,我收到 200 个 OK 响应。
{"ok":true,"files":[{"id":"XXXXXXX","created":XXXXXXXX,"timestamp":XXXXXXXX,"name":"test.txt","title":"Slack API updates Testing","mimetype":"","filetype":"","pretty_type":"","user":"XXXXXXXXX","user_team":"XXXXXXXXX","editable":false,"size":50123,"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\/XXXXXXXXX-XXXXXXX\/test.txt","url_private_download":"https:\/\/files.slack.com\/files-pri\/XXXXXXXXX-XXXXXXX\/download\/test.txt","media_display_type":"unknown","permalink":"https:\/\/XXXXXXXX.slack.com\/files\/XXXXXXXXX\/XXXXXXX\/test.txt","permalink_public":"https:\/\/slack-files.com\/XXXXXXXXX-XXXXXXX-XXXXXXXX","comments_count":0,"is_starred":false,"shares":{},"channels":[],"groups":[],"ims":[],"has_more_shares":false,"has_rich_preview":false,"file_access":"visible"}],"warning":"missing_charset","response_metadata":{"warnings":["missing_charset"]}}
疑问和问题: 1-如何确定第一个请求中的 length= (files.getUploadURLExternal ) 2- 即使我提供了channel_id,文件仍然没有上传到 Slack 频道。
文档: https://api.slack.com/methods/files.completeUploadExternal https://api.slack.com/methods/files.getUploadURLExternal
您跳过了一步。您必须将 POST 发送到第一步返回给您的 URL。在那篇文章中,您还进行文件上传。
第二步应该是:
curl -F filename="@$filename" -H "Authorization: Bearer $SLACK_KEY" -v POST $upload_url
那么你的第二步应该是第三步。
就获取字节大小而言
stat --printf="%s" file
(如果您使用的是 bash)