10

I'm using Google App Engine with Python 2.7 and I'm trying to use an svg-file as a sprite-sheet.

For some reason this works fine on Win7 and Ubuntu, but not on Vista or Mac (Using the latest Chrome and Firefox in each case).

Here it's sent with mime-type "application/octet-stream" and the browsers prompts to download it, instead of displaying it.

I tried overriding the mime-type in my app.yaml like this:

- url: /img/.*\.svg
  static_dir: public/img
  mime_type: image/svg+xml

- url: /img
  static_dir: public/img

But that didn't change anything.

I also tried to route requests for svg-files through their own url like this

- url: /img/svg
  static_dir: public/img
  mime_type: image/svg+xml

- url: /img
  static_dir: public/img

But that results in the file being sent with mime-type "img/png", so the browser will at least try to display it, but can't.

Just to make sure, I tried each combination as stated and also with the headers-options:

- url: /img/svg
  static_dir: public/img
  http_headers:
    mime-type: image/svg+xml

Without success.

Any help please?

[edit]

After some more testing, it seems like on Ubuntu using the local app-launcher, it sends the svg as text/html and when deployed it uses application/octet-stream, regardless of what I put in the app.yaml.

Does anybody have experience with this? The only way I can solve this is to insert the svg-code into the page directly, which kinda sucks. It's a graphic and I want to treat it that way.

[more edit]

In the end, I put this in the yaml-file and it seems to work:

- url: /img/.*\.svg
  static_dir: public/img
  http_headers:
    content_type: image/svg+xml

- url: /img
  static_dir: public/img
HumanCatfood
  • 960
  • 1
  • 7
  • 20

1 Answers1

10

Try:

http_headers:
  content-type: image/svg+xml
flamingcow
  • 341
  • 2
  • 7
  • Thanks, that seems to work fine! Any idea why it behaves so differently on the different client computers? – HumanCatfood Jun 10 '14 at 08:52
  • 1
    Serving responses with an incorrect MIME type is always going to have unpredictable results. Some clients will try to guess; they all have different rules for how that guess works, and some may rely on operating system support to do the guessing and/or display. It's more aggravating that AppEngine can't guess the right MIME type; that seems pretty simple in this case. – flamingcow Jun 10 '14 at 18:35
  • Why does the `mime_type` flag in the `.yaml` file not work? It's in their documentation: https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers Seems like a GAE bug. – speedplane Dec 14 '15 at 03:46