How to Change File Extension for Images on Cloudflare CDN?

Hello everyone, I'm encountering an issue with a GIF image I uploaded to Cloudflare CDN. Here's the situation: 1. I uploaded a GIF to Cloudflare CDN. 2. When I try to share it on Discord, it's being sent as a static image. 3. Opening the same link in a browser shows the animated GIF correctly. 4. Discord only recognizes GIFs if they have a .gif file extension. 5. The current URL doesn't include the .gif extension. 6. Manually adding .gif to the URL results in a "malformed URL" error. Is there a way to add or change the file extension for images stored on Cloudflare CDN without breaking the URL? Any help or suggestions would be greatly appreciated. Thanks in advance!
4 Replies
Chaika
Chaika3mo ago
You can use Custom Domains and something like the rule they recommend with a few modifications: https://developers.cloudflare.com/images/manage-images/serve-images/serve-from-custom-domains/ Something like this works well:
Cloudflare Docs
Serve images from custom domains | Cloudflare Image Optimization docs
Image delivery is supported from all customer domains under the same Cloudflare account. To serve images through custom domains, an image URL should be adjusted to the following format:
No description
MrCRACK
MrCRACKOP3mo ago
Thank you very much!
Chaika
Chaika3mo ago
URI Path Starts With /images/ and Hostname eq the image subdomain you want (or on main domain if that's fine/doesn't conflict. You can pick a diff subpath other then images here as long as you change it everywhere then rewrite path to dynamic concat( "/cdn-cgi/imagedelivery/<accountHash>", substring(http.request.uri.path, 7, -4), "/public") // we skip /images and append /public to the end for that variant, can change if needed. Grab your account hash from the images tab. This results in something like this /images/2f720aed-96fa-4a98-4e26-22cf8328fc00.gif (the guid being the normal images image guid)-> being written to /cdn-cgi/imagedelivery/DoE71rnH9coHrk8hcmlMVA/2f720aed-96fa-4a98-4e26-22cf8328fc00/public (This is Rules -> Transform Rule -> Rewrite URL) kind of annoying that it's semi difficult but lets you customize it pretty well on your custom domain. If you wanted to support non-gifs on the special images path you could add a condition there URL Path ends with .gif and then make a second version of that rule URL Path does not end with .gif and change the substring from -4 on the end to 0
MrCRACK
MrCRACKOP3mo ago
Thanks for answering
Want results from more Discord servers?
Add your server