Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serve Static PNG files with an "image/png" content type, not "image/x-png"

I'm using google app engine with Python and have a couple static .png image files but they are all being served with an "image/x-png" content-type. This is a problem when I use a browser like chrome and try to view these images as the content-type is unrecognized, which forces chrome to download it as binary, rather than displaying the image.

How can I make App Engine serve these with the proper "image/png" mime type?

like image 387
DerekR Avatar asked Mar 02 '13 21:03

DerekR


People also ask

Are PNG files static?

A transparent background allows designers to embed graphics into other images rather easily without requiring more complicated steps in post editing. PNG is ideal for static images, logos, prints and other images with transparent background.

How do I open a PNG file in my browser?

That means if you want to view a PNG file, you simply need to double-click it and it should open in the default viewer on your computer. You can also view a PNG file by dragging it into any web browser (or use CTRL + O to browse for the file and then open it in a browser).

Can you use PNG on WordPress?

Although they are usually larger in size than the equivalent JPEG image, PNG images have become quite popular on the Web and are fully supported by WordPress. You can insert a PNG image file into a WordPress blog post or page just as you would any other image.


1 Answers

Assuming you are using Java, this is specified normally in the mime-mapping section in the web.xml file. See eg here or here.

In your case, I'd try

 <mime-mapping>
        <extension>png</extension>
        <mime-type>image/png</mime-type>
 </mime-mapping>

In Python, it seems you should add some handler to your app.yaml with the appropiate mime_type, for example (replace with your own url and static_dir) :

handlers:
- url: /static/*.png
  static_dir: static
  mime_type: image/png
like image 199
leonbloy Avatar answered Oct 19 '22 10:10

leonbloy