Serving SVG / SVGZ images via R2


Staff member
By default, Cloudflare R2 analyzes the object when it's uploaded to it's bucket and makes a determination about what the content type should be when that object is served. Normally this works fine, but SVG/SVGZ images are a little bit of an edge case because at the core they are actually text/XML files so Cloudflare will see the content as an XML file. The issue is when you are using a public domain to serve the images directly from your bucket and Cloudflare is telling browsers it's not an image, rather than XML document.

Thankfully, Cloudflare gives you a way to override the content type based on the URI extension. If you want Cloudflare to serve SVG/SVGZ images as images (rather than XML documents), go into your Cloudflare dashboard to create a response header rule: your zone -> Rules -> Transform Rules -> Modify Response Header -> Create rule

You want the rule to look like this: