khellang / MimeTypes

A simple lookup from file name/extension to MIME/media type, generated from mime-db, which in turn is compiled from IANA, Apache and nginx's MIME types.
Apache License 2.0
93 stars 23 forks source link

Add a simple method that can be used to validate a provided mimetype #6

Closed Aumnia closed 4 years ago

Aumnia commented 7 years ago

I always end up adding this to the generated source file so decided I would see if you wanted to add it to the project. It's a dead simple way to ensure uploaded files always have a valid mime-type associated with them.

Thanks for keeping this repo up to date!

/Carl

khellang commented 7 years ago

I think I'm fine taking something like this, but I"m not sure I like the name of the method. What is it validating? The format? That it is a valid media type? That it's registered? Why does it return a string and not a bool?

Maybe if we expose a method like IsRegistered or Contains, you could do the fallback uourself?

Aumnia commented 7 years ago

No problem with whatever you want to call the method and have it return. My most basic need is just access to the TypeMap data structure to validate a media type has been registered.

I wrote it this way only because it lets me do:

uploadFile.MimeType = MimeTypes.Validate(source.ContentType)