discord / discord-api-docs

Official Discord API Documentation
https://discord.com/developers/docs/intro
Other
5.96k stars 1.26k forks source link

HTTP 415 for image embed #6684

Open kik-tibia opened 8 months ago

kik-tibia commented 8 months ago

Description

I have two identical image URLs, here: https://tibia.fandom.com/wiki/Special:Redirect/file/Nightfiend.gif https://tibia.fandom.com/wiki/Special:Redirect/file/Ravenous_Hunger.gif Discord is only embedding the first URL.

Steps to Reproduce

Send the following discord message:

https://tibia.fandom.com/wiki/Special:Redirect/file/Nightfiend.gif https://tibia.fandom.com/wiki/Special:Redirect/file/Ravenous_Hunger.gif

Expected Behavior

Two identical GIFs should be shown.

Current Behavior

Only the first image, Nightfiend.gif, is shown. Ravenous_Hunger.gif is not converted into an image. This affects bots and users. Additionally, running the 2nd URL through discord's Embed Debugger returns this warning:

It's not clear to me if there is a problem with the image URL or with Discord. When I download both images, they are identical (same md5sum), and the URLs both have the same HTTP headers and similar redirect steps.

Screenshots/Videos

image The first message demonstrates the problem, in that only one image is shown. The second message (with Troll.gif and Young_Troll.gif) demonstrates the expected behaviour for two identical images: both are shown.

Client and System Information

Windows 11 desktop client, Arch Linux desktop client.

kik-tibia commented 8 months ago

I did some more digging. Taking a look at the network requests sent by the Embed Debugger, it is calling the unfurler api to generate the thumbnail. For the working image, Nightfiend.gif, the headers in the JSON response are:

    "headers": {
      "content-disposition": "inline; filename=\"Nightfiend.gif\"; filename*=UTF-8''Nightfiend.gif",
      "content-type": "image/gif"
    }

However, for the broken image, Ravenous_Hunger.gif, the content-type is webp:

    "headers": {
      "content-disposition": "inline; filename=\"Ravenous_Hunger.webp\"; filename*=UTF-8''Ravenous_Hunger.webp",
      "content-type": "image/webp"
    }

So for some reason, the unfurler thinks the broken image is a webp.

Next, I followed the image redirect to its destination and took a look at the content type.

curl -i "https://static.wikia.nocookie.net/tibia/images/4/4f/Ravenous_Hunger.gif/revision/latest?cb=20180125184028&path-prefix=en" content-type: image/gif

If I include the Accept: image/webp header, then the server does return a webp image instead. curl -i -H 'Accept: image/webp' "https://static.wikia.nocookie.net/tibia/images/4/4f/Ravenous_Hunger.gif/revision/latest?cb=20180125184028&path-prefix=en" content-type: image/webp

So, one possibility is that somewhere in the unfurler API is including the Accept: image/webp header despite Discord not supporting webp?

okdargy commented 4 months ago

Having the same issue, an embed, with the same redirect as another working (200) embed, is giving a 415 status code. Even with analyzing with the Discord embed debugging tool, it shows the same result as the other URL.

This is only effecting one of my different endpoint patterns (/t/*) which doesn't make any sense.

✅ Working example: https://www.tnktok.com/@mixedwithology/photo/7377433299616320814.jpg

image image

❌ Non-working example: https://www.tnktok.com/t/ZPRKg8t3d.jpg

image image