<p>On old versions of python, the python library mimetypes didnt have a definition for svg file types. </p>

<p>See this issue: <a href="https://bugs.python.org/issue19377" rel="nofollow noreferrer">https://bugs.python.org/issue19377</a></p>

<p>I added <code>'.svg' : 'image/svg+xml',</code> into the <code>types_map</code> in <code>mimetypes.py</code> and then the aws cli got the correct type for SVGs.</p>

CC BY-SA 4.0
2019-02-25T17:56:47.963Z
2019-02-25T17:56:47.963Z
scottarver
<p>Your SVG file is probably missing the the XML declaration at the top (<code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</code>). PHP's FileInfo detects XML files (which SVG is) without that declaration as text/html files.</p>

<p>Lots of SVG editors/exporters will (annoyingly) omit that.</p>

CC BY-SA 3.0
2016-11-15T23:39:13.910Z
Aha! That fixed it. I wonder why PHP doesn't rely on the extension rather than some optional doc type definition.

Anyway, *shakes fist @ Adobe Illustrator team*.
mrtobo
CC BY-SA 3.0
2016-11-15T23:53:58.743Z
Probably because extensions can lie. :)  `mv img.jpg img.svg`
Brad Bell
CC BY-SA 3.0
2016-11-16T15:57:19.990Z
That seems fair, but still it a much more difficult mistake to make than your SVG editor silently omitting an arcane xml node. ¯\_(ツ)_/¯
mrtobo
CC BY-SA 3.0
2016-11-16T17:48:16.087Z
Not so much a mistake, but could be used to exploit servers potentially.  i.e. if you restrict uploads based only on file extensions, but then rename `mybadscript.exe` to `cutekitten.jpg`, you've delivered a payload and now just need to find a way to execute it.
Brad Bell
CC BY-SA 4.0
2019-01-17T11:39:36.147Z
it is working for me. It really great solutions
Anwar
CC BY-SA 3.0
2016-11-15T23:20:56.290Z
2016-11-15T23:20:56.290Z
Brad Bell
<p>I've setup an S3 asset source for images and it's working well for everything but SVGs.</p>

<p>SVGs are uploaded with the default content-type of <code>binary/octet-stream</code> where the correct content-type would be <code>image/svg+xml</code>.</p>

<p>Am I doing something wrong or is this a bug?</p>

<assets><s3>
Incorrect content/mime-type on S3 SVG upload
# Incorrect content/mime-type on S3 SVG upload

(Asked by: username_0 on 2016-11-15)

I've setup an S3 asset source for images and it's working well for everything but SVGs.

SVGs are uploaded with the default content-type of `binary/octet-stream` where the correct content-type would be `image/svg+xml`.

Am I doing something wrong or is this a bug?

**Tags:** assets, s3


---

## 2 answers

### Answer by username_2 on 2016-11-15. Score: 5 | Accepted answer

Your SVG file is probably missing the the XML declaration at the top (`xml version="1.0" encoding="UTF-8"?`). PHP's FileInfo detects XML files (which SVG is) without that declaration as text/html files.

Lots of SVG editors/exporters will (annoyingly) omit that.

> **Comments:**
> **username_0**: Aha! That fixed it. I wonder why PHP doesn't rely on the extension rather than some optional doc type definition.  Anyway, *shakes fist @ Adobe Illustrator team*.  
> **username_2**: Probably because extensions can lie. :)  `mv img.jpg img.svg`  
> **username_0**: That seems fair, but still it a much more difficult mistake to make than your SVG editor silently omitting an arcane xml node. ¯\_(ツ)_/¯  
> **username_2**: Not so much a mistake, but could be used to exploit servers potentially.  i.e. if you restrict uploads based only on file extensions, but then rename `mybadscript.exe` to `cutekitten.jpg`, you've delivered a payload and now just need to find a way to execute it.  
> **username_3**: it is working for me. It really great solutions  

---

### Answer by username_1 on 2019-02-25. Score: -1

On old versions of python, the python library mimetypes didnt have a definition for svg file types.

See this issue: <https://bugs.python.org/issue19377>

I added `'.svg' : 'image/svg+xml',` into the `types_map` in `mimetypes.py` and then the aws cli got the correct type for SVGs.


---

