Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting extension from a given mime type #534

Closed
jacargentina opened this issue Jan 29, 2020 · 4 comments
Closed

Getting extension from a given mime type #534

jacargentina opened this issue Jan 29, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@jacargentina
Copy link

Is your feature request related to a problem? Please describe.
I have an Image instance, and I'm. detecting its mime type, then I need to build a "filename" for it from a given title string; I need to put the right extension for the mime so when I send that content via WordpressPCL library, It gets correctly detected and processed.

var image = ....;
var mimeType = ImageCodecInfo.GetImageEncoders().First(codec => codec.FormatID == image.RawFormat.Guid).MimeType;
var filename = ...

I'm looking on how to reuse MimeTypes class from this MimeKit as it is already a dependency on my c# project for email; but it does only the reverse thing (from a filename get the mime type);

Describe the solution you'd like
Would be nice to to the other way too; from a given mime type, get the extension; so I can build the correct filename.

Describe alternatives you've considered
Copy and paste the already existing mapping dictionary from MimeTypes on my code.......

@jacargentina
Copy link
Author

I can add another dependency to my project like this one https://github.com/samuelneff/MimeTypeMap

But as I stated previously, having already MimeKit , would be nice to avoid more dependencies and have a new method on it.

@wartab
Copy link

wartab commented Jan 31, 2020

It seems to me that this is completely out of scope for a library like MimeKit. MimeKit's purpose is to parse and also build MIME messages.
Guesstimating what file extension could be associated with a certain media type has nothing to do with that.

@jacargentina
Copy link
Author

@wartab Look MimeTypes.GetMimeType. Basically that method is doing a guessing for the mime type by looking at the filename.

I think the reverse is in scope for the library just because the code is already there

jstedfast added a commit that referenced this issue Feb 1, 2020
@jstedfast
Copy link
Owner

Implemented.

@jstedfast jstedfast added the enhancement New feature or request label Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants