Skip to content

Conversation

@RyanGaudion
Copy link

MimeTypeMap.GetExtension("image/jpg") - throws an error when it shouldn't

@samuelneff
Copy link
Owner

image/jpeg is the correct mime type. See https://datatracker.ietf.org/doc/html/rfc2158#section-3.1

That said,while we only support one mime type per extension, we do support multiple mime types pointing to the same extension. So while MimeTypeMap.GetMimeType("jpg") will always return image/jpeg, we can support both MimeTypeMap.GetExtension("image/jpeg") and MimeTypeMap.GetExtension("image/jpg") both returning .jpg.

To do this, instead of adding a mapping for jpg to image/jpg you need to add the reverse mapping (see end of list). I believe when using a manual reverse mapping all of the mappings must be specified, so to get what you want you'll need to add

{"image/jpg", ".jpg"},
{"image/jpeg", ".jpg"},

Then you can lookup the extension by either mime type and it'll maintain backwards compatibility.

Copy link
Owner

@samuelneff samuelneff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment about using a reverse mapping instead.

@bjornmicallef
Copy link

If I may, I think the changes submitted by @RyanGaudion still need to be merged in as I'm also getting an exception when trying to get file extension for mime type "image/jpg"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants