Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

php - Can I upload an image as attachment with Slack API?

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

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

1 Reply

0 votes
by (71.8m points)

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 [email protected] -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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...