2

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"
        }
    ]
}
4
  • Why not save->send->delete? Sep 1, 2017 at 8:06
  • @ThomasMoors that won't work. the moment you delete the image on your server also Slack will not show it any longer Sep 1, 2017 at 11:16
  • @ErikKalkoken If you send it as an attachment that would not be true? Like if you send it from your PC Sep 1, 2017 at 11:34
  • I think you mean image uploads, that is different from attachments. See my answer for details. Sep 1, 2017 at 11:37

1 Answer 1

4

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.

1
  • 1
    @Sarvarnabi Khan if this answer solved your question, please consider marking it as solution. So that this question can be closed. Thank you! Feb 22, 2018 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.