Closed bitinn closed 9 years ago
It is only meant to look up the mime for a file extension. If you already have the mime, then there is nothing to even look up...
If you can provide more concrete examples of what, exactly, you are trying to do and expecting, then I can see what help I can provide, but otherwise all I can say is that mime.lookup
is designed only to accept a file name or extension and look up the matching mime type; application/x-shockwave-flash
is not distinguishable from a file named x-shockwave-flash
in the folder application
.
Please also let us know how we can expand the documentation at https://github.com/jshttp/mime-types#mimelookuppath to make it clear the only acceptable input to mime.lookup
is a file path.
my code is a big complicated, but it comes down to:
<meta property="og:image:type" content="image/png">
into image/png
image/png
is valid by calling mime.lookup('image/png')
and I have switched to mime.extension
, it works as long as meta is not messed up, I guess it's the closest to a validation check? or maybe I should use mime-db
directly? should mime-types
provide such an API for validation?
As for the doc, it says All functions return false if input is invalid or not found
, and my use-case is exactly that, to check if content-type is a known and valid content-type.
or maybe I should use mime-db directly?
ah, yes, with that explanation, that is exactly what I was going to suggest.
As for the doc, it says All functions return false if input is invalid or not found
Right, and mime.lookup
is defined as Lookup the content-type associated with a file.
, and the file you gave it was application/x-shockwave-flash
, which is the file called x-shockwave-flash
in a folder called application
, and since that file didn't have an extension, it returned false
, for invalid input.
thx, i see no point to keep this open then.
Not sure if you consider this an edge case, but I just tried to do this:
I could be using
mime.extension
instead but it doesn't try to correct any input, and I was testing mime type obtained from parsing opengraph meta, ref: http://ogp.me/#structured, so I would like to correct them if possible, but I understand that may not be whatmime.lookup
designed to do.