Google App Engine is sending SVG with wrong mime-type

守給你的承諾、 提交于 2020-05-25 04:29:46

问题


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

回答1:


Try:

http_headers:
  content-type: image/svg+xml


来源:https://stackoverflow.com/questions/24106691/google-app-engine-is-sending-svg-with-wrong-mime-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!