我已经在项目中使用cURL集成了Slack API. 我想发送图像作为附件.在image_url中发送完整图像路径时,它可以工作.但是,当我将该图像转换为base64字符串,然后用image_url传递时,它不会作为附件使用.
I have integrated Slack API using cURL in my project. I want to send an image as my attachment. It works while sending full image path in image_url. But when I convert that image to base64 string and then pass it with image_url it doesn't go as attachment.
所以基本上,我想发布base64字符串作为我的图像附件.因为我不想将图像存储在服务器上.
So basically I want to post base64 string as my image attachment. Because I don't want to store the image on my server.
{"attachments": [ { "fallback": "Required text summary of the attachment that is shown by clients that understand attachments but choose not to show them.", "image_url":"", "text":"", "color":"#7CD197" } ] }推荐答案
您不能提交完整图像作为附件,只能提交图像的URL.
You can not submit a full image as attachments, only URLs to an image.
如果要将图像上传到Slack,可以使用 files.upload .这是一个从Slack文档中上传GIF图像的curl示例:
If you want to upload an image to Slack you can do so by using files.upload. Here is a curl example for uploading a GIF image from the Slack documentation:
curl -F file=@dramacat.gif -F channels=C024BE91L,#general -F token=xxxx-xxxxxxxxx-xxxx slack/api/files.upload一种替代方法是使用图片托管服务商(例如 imgur )上传并存储您的图片(通过其API).然后,您可以在附件中包含图像URL.
An alternative is to use an image hoster (e.g. imgur) to upload and store your image (through their API). Then you can include the image URL in your attachment.
我个人更喜欢第二种选择,因为它更灵活地在消息和图像中包含图像URL,然后不会减少Slack上的宝贵存储空间.
I personally prefer the second option, since its more flexible to include image URLs in messages and images then do not reduce your precious storage space on Slack.
更多推荐
我可以使用Slack API上载图片作为附件吗?
发布评论