如何使用正确的文件类型将图像上传到SLACK API file.upbase作为base64的端点?

时间:2019-04-19 11:58:35

标签: base64 slack-api

我正在尝试将图像上传到files.upload。从文档中,我读到可以发送图片

  • 通过 file自变量
  • 编码为multipart/form-data的二进制文件
  • 还是字符串?通过 content自变量
  • 编码为application/x-www-form-urlencoded

关于 content自变量形式的详细信息很少,我希望通过 base64 字符串发送图像。

问题:我可以上载base64字符串,但是松弛不会将mime类型解释为text/plain

slack,即使 filetype参数设置为png

是否可以通过base64字符串将图像上传到松弛状态?


我在以下POST调用中使用了Postman: Postman 和响应:

  {
        "ok": true,
        "file": {
            "id": "FJ1B1MW64",
            "created": 1555670784,
            "timestamp": 1555670784,
            "name": "hello.png",
            "title": "hello",
            "mimetype": "text/plain",
            "filetype": "text",
            "pretty_type": "Plain Text",
            "user": "UJ28E2AP9",
            "editable": true,
            "size": 40083,
            "mode": "snippet",
            "is_external": false,
            "external_type": "",
            "is_public": true,
            "public_url_shared": false,
            "display_as_bot": false,
            "username": "",
            "url_private": "https://files.slack.com/files-pri/TJ0BYCWBX-FJ1B1MW64/hello.png",
            "url_private_download": "https://files.slack.com/files-pri/TJ0BYCWBX-FJ1B1MW64/download/hello.png",
            "permalink": "https://santpacia3.slack.com/files/UJ28E2AP9/FJ1B1MW64/hello.png",
            "permalink_public": "https://slack-files.com/TJ0BYCWBX-FJ1B1MW64-c64922d523",
            "edit_link": "https://santpacia3.slack.com/files/UJ28E2AP9/FJ1B1MW64/hello.png/edit",
            "preview": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8YAAABuCAYAAADlNgrfAAAMRWlDQ1BJQ0MgUHJvZmlsZQAASImVVwdUU8kanltSIbTQpYTeRCnSpYTQIlWqYCMkgYQSYkIQsSuLCq5dRMCGrooouhZA1oq9LIq9PxRRUXTRFRsqb1JAV89777z/nLnz5Z9/vr9k7twZADRrOGJxLqoFQJ6oQBIfHswYl5rGIHUCFOgCCqACAw5XKmbGxUUBKIP9P+XdDYDI+6vOcq6fx/+raPP4Ui4ASBzEGTwpNw/i/QDgJVyxpAAAojfUW00tEMvxBIh1JTBAiMVynKXEJXKcocSVCpvEeBbEOwEgq3M4kiwANJqhnlHIzYI8GrcgdhHxhCIANMkQB3AFHB7EERAPz8vLl2NoB+wzvuPJ+gdnxhAnh5M1hJW5KIQcIpSKcznT/s9y/G/Jy5UN+rCFTV0giYiX5wzrdisnP1KO1SHuEWXExEKsA/EHIU9hDzFKFcgikpT2qAlXyoI1A/oQu/A4IZEQm0AcJsqNiVLpMzKFYWyI4QpBi4QF7ETV3IV8aWiCirNGkh8fO4gzJSymam4DR6LwK7c/KctJYqr4bwn47EH+t8WCxBRlzBi1UJgcA7EGxPrSnIRIpQ1mXSxgxQzaSGTx8vitIfbli8KDlfzYpExJWLzKXpInHcwXWygQsmNUuKpAkBih4tnJ5SjiN4S4mS9iJg3y8KXjogZz4fFDQpW5Y5f5oiRVvliHuCA4XjX3jTg3TmWPU/m54XK9JcQm0sIE1Vw8oAAuSCU/HiMuiEtUxolnZHPGxCnjwYtAFGCBEMAAMtgyQD7IBsK2nqYe+Es5EgY4QAKyAB84qzSDM1IUIyL4TADF4CVEfCAdmhesGOWDQqj/MqRVPp1BpmK0UDEjBzyBOA9Eglz4W6aYJRrylgweQ43wJ+9cGGsubPKxn3VMqIlSaWSDvAzNQUtiKDGEGEEMIzrgxngA7odHwWcQbG64N+4zGO...",
            "preview_highlight": "<div class=\"CodeMirror cm-s-default CodeMirrorServer\" oncopy=\"if(event.clipboardData){event.clipboardData.setData('text/plain',window.getSelection().toString().replace(/\\u200b/g,''));event.preventDefault();event.stopPropagation();}\">\n<div class=\"CodeMirror-code\">\n<div><pre>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8YAAABuCAYAAADlNgrfAAAMRWlDQ1BJQ0MgUHJvZmlsZQAASImVVwdUU8kanltSIbTQpYTeRCnSpYTQIlWqYCMkgYQSYkIQsSuLCq5dRMCGrooouhZA1oq9LIq9PxRRUXTRFRsqb1JAV89777z/nLnz5Z9/vr9k7twZADRrOGJxLqoFQJ6oQBIfHswYl5rGIHUCFOgCCqACAw5XKmbGxUUBKIP9P+XdDYDI+6vOcq6fx/+raPP4Ui4ASBzEGTwpNw/i/QDgJVyxpAAAojfUW00tEMvxBIh1JTBAiMVynKXEJXKcocSVCpvEeBbEOwEgq3M4kiwANJqhnlHIzYI8GrcgdhHxhCIANMkQB3AFHB7EERAPz8vLl2NoB+wzvuPJ+gdnxhAnh5M1hJW5KIQcIpSKcznT/s9y/G/Jy5UN+rCFTV0giYiX5wzrdisnP1KO1SHuEWXExEKsA/EHIU9hDzFKFcgikpT2qAlXyoI1A/oQu/A4IZEQm0AcJsqNiVLpMzKFYWyI4QpBi4QF7ETV3IV8aWiCirNGkh8fO4gzJSymam4DR6LwK7c/KctJYqr4bwn47EH+t8WCxBRlzBi1UJgcA7EGxPrSnIRIpQ1mXSxgxQzaSGTx8vitIfbli8KDlfzYpExJWLzKXpInHcwXWygQsmNUuKpAkBih4tnJ5SjiN4S4mS9iJg3y8KXjogZz4fFDQpW5Y5f5oiRVvliHuCA4XjX3jTg3TmWPU/m54XK9JcQm0sIE1Vw8oAAuSCU/HiMuiEtUxolnZHPGxCnjwYtAFGCBEMAAMtgyQD7IBsK2nqYe+Es5EgY4QAKyAB84qzSDM1IUIyL4TADF4CVEfCAdmhesGOWDQqj/MqRVPp1BpmK0UDEjBzyBOA9Eglz4W6aYJRrylgweQ43wJ+9cGGsubPKxn3VMqIlSaWSDvAzNQUtiKDGEGEEMIzrgxngA7odHwWcQbG64N+4zGO...</pre></div>\n</div>\n</div>\n",
            "lines": 2,
            "lines_more": 1,
            "preview_is_truncated": true,
            "comments_count": 0,
            "shares": {
                "public": {
                    "CHNUYS3U3": [
                        {
                            "reply_users": [],
                            "reply_users_count": 0,
                            "reply_count": 0,
                            "ts": "1555670784.002500",
                            "channel_name": "everyone",
                            "team_id": "TJ0BYCWBX"
                        }
                    ]
                }
            },
            "channels": [
                "CHNUYS3U3"
            ],
            "groups": [],
            "ims": [],
            "has_rich_preview": false
        }
    }

0 个答案:

没有答案