我可以使用Slack API上载图片作为附件吗? [英] Can I upload an image as attachment with Slack API?

查看:73
本文介绍了我可以使用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 https://slack.com/api/files.upload

一种替代方法是使用图片托管服务商(例如 http://imgur.com )上传并存储您的图片(通过其API).然后,您可以在附件中包含图像URL.

An alternative is to use an image hoster (e.g. http://imgur.com) 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上载图片作为附件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆