Curl命令行中files.getUploadURLExternal的正确使用

问题描述 投票:0回答:1

我正在使用:

curl -v -F file=@/tmp/x.png -F "initial_comment" -F channels='xyz' -H "Authorization: Bearer oauth" https://slack.com/api/files.upload

效果仍然很好,但是

file.upload
很快就会停产。

现在,阅读文档后,我尝试了:

curl \
    -H "Authorization: Bearer xxx" \
    -H "Content-Type: application/json" \
    -F "filename=/tmp/img.png" \
    -F "length=$(wc -c < /tmp/img.png)" \                                           
    https://slack.com/api/files.getUploadURLExternal | jq .

curl -X POST \
    -H "Authorization: Bearer xxx" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -F "filename=@/tmp/img.png" \
    -F "length=$(wc -c < /tmp/img.png)" \
    https://slack.com/api/files.getUploadURLExternal | jq .

但是第一个出现 JSON 错误:

{
  "ok": false,
  "error": "invalid_arguments",
  "warning": "missing_charset",
  "response_metadata": {
    "messages": [
      "[ERROR] missing required field: length",
      "[ERROR] missing required field: filename"
    ],
    "warnings": [
      "missing_charset"
    ]
  }
}

第二个命令:

{
  "ok": false,
  "error": "invalid_arg_name"
}

如何正确传递参数?该文档在 Curl 中没有示例。我的字符集是

utf8
,一样,怎么传递呢?

rest curl slack slack-api
1个回答
0
投票

好吧,通过尝试不同的方法找到了答案:

length=$(wc -c < /tmp/img.png)
curl \
    -H "Authorization: Bearer xxx" \
    -H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" \
    -d "filename=test" \
    -d "length=$length" \
    https://slack.com/api/files.getUploadURLExternal | jq .
© www.soinside.com 2019 - 2024. All rights reserved.