# Using MIME type to detect embedded image

**URL:** https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978
**Category:** Feature
**Created:** [August 13, 2017, 6:52pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978 "2017-08-13T18:52:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [August 13, 2017, 6:52pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/1 "2017-08-13T18:52:24Z")

</div>

Continuing the discussion from [Add setting to disable hotlinking of large image files](https://meta.discourse.org/t/add-setting-to-disable-hotlinking-of-large-image-files/67909/9):

I’d like to propose detection of images by MIME type, not by extension.

Use case:

I put JPG url on line:

 ![full](https://global.discourse-cdn.com/meta/original/4X/b/2/1/b217c858e8a4f37b29727b48b01d9f4b12a0b12f.jpeg)  
File doesn’t have JPG extension, but content-type is correctly sent, so I’d like to see Discourse to automatically update it to img tag, show inline and even hotlink.

 ![image](https://global.discourse-cdn.com/meta/original/3X/6/3/6336327e56d00e70fc74c9775fc5559b2e91b2e7.png)

I believe it would be beneficial to detect photo for oneboxing (updating to img tag) not from extension like it is being used currently, but from MIME type.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 13, 2017, 9:07pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/2 "2017-08-13T21:07:49Z")

</div>

Easy to work around though just add `?x=.jpg` to the end of any URL.

`https://freecannabis.com/media/dscf1924.36/full?x=.jpg`

 ![](https://global.discourse-cdn.com/meta/original/3X/c/7/c705e38982bb61843e9d8d29d8e82843935b5b58.jpg)

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [August 13, 2017, 9:12pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/3 "2017-08-13T21:12:36Z")

</div>

Thanks. But that doesn’t quite solve the problem. I’m already using workaround to add img tag manually. My users are not technically skilled so automatic form of hotlinking would be great.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 13, 2017, 9:14pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/4 "2017-08-13T21:14:03Z")

</div>

I think it is super bad form to have images that look like HTML web pages so I would object to this being supported as it encourages super bad web hosting habits.

---

<div class="post-metadata">

### Author: ![Overgrow](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/overgrow/32/478189_2.png) [@Overgrow](https://meta.discourse.org/u/Overgrow)
#### Post date: [August 13, 2017, 9:14pm UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/5 "2017-08-13T21:14:51Z")

</div>

I agree it is bad practice of the image hoster, but you know - " be tolerant in what you accept "

> **[Robustness principle](https://en.wikipedia.org/wiki/Robustness_principle)**
>
> In computing, the robustness principle is a design guideline for software that states: "be conservative in what you do, be liberal in what you accept from others". It is often reworded as: "be conservative in what you send, be liberal in what you accept". The principle is also known as Postel's law, after Jon Postel, who used the wording in an early specification of TCP.
> In other words, programs that send messages to other machines (or to other programs on the same machine) should conform comple...

And second, we already are pinging the URL, so why not use it to our benefit?

[edit]  
Funny side note: I’ve just found that image hoster is using Xenforo Media Gallery paid plugin 🙂

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [August 20, 2017, 1:43am UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/8 "2017-08-20T01:43:54Z")

</div>

> [@codinghorror](#):
>
> I think it is super bad form to have images that look like HTML web pages so I would object to this being supported as it encourages super bad web hosting habits.

I’m going to disagree with you here. When you get the “Content-Type:” header, that’s when you know what you are dealing with. Otherwise a URL without an extension _doesn’t look like anything_, not “looks like HTML”.

This is how content negotiation on the web is supposed to work. I should be able to make a directory full of files, and return different versions of them depending on the “Accept” headers the browser offers. If you don’t explicitly say “Accept: image/x-mycoolformat”, but just a “Accept: _/_”, then maybe I want to hand you image/jpeg, but otherwise give you mycoolformat.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [August 20, 2017, 2:11am UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/9 "2017-08-20T02:11:08Z")

</div>

By that logic, page titles and urls also don’t matter. But we all know they do. So I violently disagree on this point.

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [August 20, 2017, 3:18am UTC](https://meta.discourse.org/t/using-mime-type-to-detect-embedded-image/67978/10 "2017-08-20T03:18:29Z")

</div>

Page titles have many uses, eg distinguishing tabs and titling bookmarks. URLs matter only because Google thinks they should. But I won’t press the point further.
