'How can I post base64 image data to a Discord webhook (without using discord.js)?

I've seen other question/answers on how to achieve this, but I do not want to use Discord.js (can't in my circumstance). I have a webhook URL and base 64 image data, but cannot find helpful documentation or otherwise documented question/answers that tells me how to properly post that image information to the webhook.

Based on the documentation (link), it seems as if I should be able to use the embed or file properties of the payload, but all examples use a direct link to the image rather than the data.

So I'm looking for the shape of the payload and what exactly form the image data should be in to be able to post via a Discord webhook.

Here's my payload from what I could gather from the docs (but this isn't correct): enter image description here



Solution 1:[1]

I think it's should look like this, refer to the doc https://discord.com/developers/docs/reference#editing-message-attachments-example-request-bodies-multipartformdata

And it will take a lot of decode/encode work to make it right without sdk by the way.

--boundary
Content-Disposition: form-data; name="payload_json"
Content-Type: application/json

{
  "content": "Hello, World!",
  "embeds": [{
    "title": "Hello, Embed!",
    "description": "This is an embedded message.",
    "thumbnail": {
      "url": "attachment://myfilename.png"
    },
    "image": {
      "url": "attachment://mygif.gif"
    }
  }],
  "message_reference": {
    "message_id": "233648473390448641"
  },
  "attachments": [{
      "id": 0,
      "description": "Image of a cute little cat",
      "filename": "file.png"
  }, {
      "id": 1,
      "description": "Rickroll gif",
      "filename": "mygif.gif"
  }]
}
--boundary
Content-Disposition: form-data; name="files[0]"; filename="file.png"
Content-Type: image/png

[image bytes]
--boundary
Content-Disposition: form-data; name="files[1]"; filename="mygif.gif"
Content-Type: image/gif

[image bytes]
--boundary--

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 katopz