Splunk Dev

Setting content-type for static content

southeringtonp
Motivator

I'm trying to serve up an SVG image from within an app.

The SVG file is in appserver/static and has a .svg file extension. I'm able to retrieve the file just fine. However, the browser either fails to render the content or renders it as plain text, presumably because SplunkWeb is giving it a Content-Type of text/plain.

Does anyone know how to override the default behaviour and tell SplunkWeb (or CherryPy?) to set the correct Content-Type of image/svg+xml?

msivill_splunk
Splunk Employee
Splunk Employee

Late response, but updating answer in case anyone hits this......

If you don't mind passing your SVG via SPL and using a custom visualisation app then Scalable Vector Graphics - Custom Visualization might be another option for you (instead of updating content type for svg)

0 Karma

southeringtonp
Motivator

After beating my head against this for quite a while, the following seems to work if you have at least one custom module being loaded. In the module's python code:

import mimetypes
if not mimetypes.inited:
    mimetypes.init()
mimetypes.add_type('image/svg+xml', '.svg', True)

The upshot is that SplunkWeb is calling cherrypy.lib.static.serve_file(), which according to this page relies in turn on the python mimetypes module.

This still isn't an ideal solution, since it requires mucking about with module python code. Anyone have a more generic approach?

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...