Reputation: 5183
I am working on an app that downloads various kinds of media from different places- a lot of them user entered. I'm discovering that a lot of the content-types found in the http response are garbage. Mostly for videos it seems. So an example would be a .wmv file somewhere on the web, but when I go grab it it says its content type is text/plain.
Is there some way to check file types besides this response content-type? I was reading a bit about magic numbers for files, but I'm not sure how reliable that is... maybe it's more reliable than the response content-type?
Suggestions or thoughts?
Upvotes: 0
Views: 1024
Reputation: 25763
The only fool proof way is to actually try and open the file (with your application) and see if it gets parsed correctly.
However, if you want an API that you can use that will try and determine what the proper MIME type is from given data you can use FindMimeFromData. While this is a native Win32 function, you can still use it through p/invoke.
Upvotes: 1