I'm using metadata-extractor to extract the meta data from image files and this is working great. What I'd like to know is if there is a way that the metadata-extractor library can tell me the type of file I'm processing. I have some files that are supported file types, but they lack a file extension. Is there an API that'll just give me the file type, assuming I'm passing in a supported file type?
Asked
Active
Viewed 2,257 times
1 Answers
3
Yes you can use the FileTypeDetector
class.
I added a page about its use to the project wiki:
https://github.com/drewnoakes/metadata-extractor/wiki/File-Type-Detection
In a nutshell:
FileType fileType = FileTypeDetector.detectFileType(myStream);
if (fileType == FileType.Jpeg) {
// ...
} else if (fileType == FileType.Png) {
// ...

Drew Noakes
- 300,895
- 165
- 679
- 742
-
Actually, `FileTypeDetector`'s constructor is private and `detectFileType()` is a static method. Other than that, the code works great. – mbmast Nov 20 '16 at 07:42
-
Thanks for letting me know. Fixed. – Drew Noakes Nov 20 '16 at 21:01
-
I noticed that FileType has no enums for MOV, MP4, M4V, 3G2, 3GP and 3GP, yet these are supported types, yes? – mbmast Nov 20 '16 at 21:25
-
@mbmast video types are currently only supported in the .NET version of the library. The code is there and it shouldn't be hard to port if someone has time to put a PR together. – Drew Noakes Nov 20 '16 at 22:58