我可以使用Slack API上载图片作为附件吗?

编程入门 行业动态 更新时间:2024-10-25 09:27:26
本文介绍了我可以使用Slack API上载图片作为附件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在项目中使用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上载图片作为附件吗?

本文发布于:2023-11-26 20:03:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   附件   图片   API   Slack

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!