How can I Serve SVG over SSL

457 views
Skip to first unread message

Jesus Noland

unread,
Jun 21, 2015, 6:08:10 PM6/21/15
to google-a...@googlegroups.com
When I run the local development environment my SVG file renders correctly on the web page but when I upload the app to my custom domain with SSL the image type is octet-stream. I have tried updating the app's YAML file but I can't get it to serve right. What do I need to do to get the SVG file to render as an image on a webpage on a custom domain with SSL?

My app is running on Python2.7 and Flask.

Your answers are great appreciated. Thanks

Michael (Cloud Platform Support)

unread,
Jun 24, 2015, 10:03:04 AM6/24/15
to google-a...@googlegroups.com, jesus...@gmail.com
Hi Jesus!

There are a few possible reasons for your application not using the correct MIME type. I'd like you to send me the contents of your app.yaml file through private message so that I may better identify a possible cause for this behavior.

Cheers!

Jesus Noland

unread,
Jun 25, 2015, 12:58:51 PM6/25/15
to google-a...@googlegroups.com
Thank you Michael I will send you a private message asap with the app.yaml code.

Michael (Cloud Platform Support)

unread,
Jun 26, 2015, 2:32:13 PM6/26/15
to google-a...@googlegroups.com, jesus...@gmail.com
Hi Jesus,

Thank you for getting back to me. I recommend adding the below to your app.yaml's handlers and trying it out then:
handlers:
- url: /(.*\.svg)
static_files: static/
\1
upload
: static/(.*\.svg)
mime_type
: image/svg+xml

This should resolve your issue.

Cheers!


On Sunday, June 21, 2015 at 6:08:10 PM UTC-4, Jesus Noland wrote:

Jesus Noland

unread,
Jun 28, 2015, 5:21:35 AM6/28/15
to google-a...@googlegroups.com, jesus...@gmail.com
Thank you! I took the code you sent and modified it and got it working.

Here's the solution for anyone else struggling with this problem. I am using Python2.7 and Flask and I want to render an SVG image in my Jinja2 template using an <img> tag.

<img draggable="false" id="background-img" alt="Litpen" title="Litpen" src="{{ url_for('static', filename='litpen-homepage.svg') }}" />

This is the app.yaml handlers code that allows this beautiful rendering to happen :)

handlers:
- url: /static/(.*\.svg)
  static_files: static/\1
  upload: static/(.*\.svg)
  mime_type: image/svg+xml

- url: /.*
  script: main.app
Reply all
Reply to author
Forward
0 new messages