42wim / matterbridge

bridge between mattermost, IRC, gitter, xmpp, slack, discord, telegram, rocketchat, twitch, ssh-chat, zulip, whatsapp, keybase, matrix, microsoft teams, nextcloud, mumble, vk and more with REST API (mattermost not required!)
Apache License 2.0
6.65k stars 618 forks source link

[api] How to use images in api properly? #2052

Open yousefmansy1 opened 1 year ago

yousefmansy1 commented 1 year ago

Describe the bug Using this site to convert to base 64, I run a sample post with image data and on discord no file is sent at all, and on telegram only a malformed file is sent. (downloading it and changing the extension makes it work as an image again, so the data is fine.)

Original PR, does not have any example. https://github.com/42wim/matterbridge/pull/1993

To Reproduce

DATA=$(cat << EOF
{
    "username": "test",
    "text": "test",
    "gateway": "test",
    "event": "",
    Extra" : {
        "file": [
            {
                "Data": ["BASE64DATA"]
            }
        ]
    }
}
EOF

)

curl -XPOST -H 'Content-Type: application/json'  -d "$DATA" http://localhost:4242/api/message#

Expected behavior Image should show, but it does not.

Screenshots/debug logs image image

Environment (please complete the following information):

Additional context

[api]
    [api.myapi]
        BindAddress="172.22.0.111:4242"
        Buffer=1000

....

[[gateway]]
name="test"
enable=true
    [[gateway.in]]
    account="api.myapi"
    channel="api"
tehsu commented 3 months ago

Do it like this instead,

         ```

'Extra':{ 'file': [ {'Data': file, 'Name': 'filename.jpeg', 'Comment': message } ] }