Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

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"
        }
    ]
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
499 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can not submit a full image as attachments, only URLs to an image.

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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...