MimeTypeMap icon indicating copy to clipboard operation
MimeTypeMap copied to clipboard

Fixed jpg Issue

Open RyanGaudion opened this issue 3 years ago • 2 comments

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

RyanGaudion avatar May 19 '21 15:05 RyanGaudion

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.

samuelneff avatar May 19 '21 15:05 samuelneff

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"

bjornmicallef avatar Oct 04 '21 11:10 bjornmicallef