A library of helper methods for your .Net, Javascript or Python projects to get mime types and general file category
Available as a nuget package, npm package, or PyPI package
1.1.7 - Updated sources, optimized generated code to be smaller and to be easier to diff future versions
1.1.3 - Updated sources, Notably the mime type for .js is now text/javascript instead of application/javascript according to the IANA standard specification
1.1.0 - Updated sources, added PDF, Presentation, and Spreadsheet file categories - formerly part of Document
dotnet add package FTTLib.dll
using FTTLib;
string mimeType = FTT.GetMimeType(@"Path\To\My\File.doc");
Console.WriteLine(mimeType);
mimeType = FTT.GetMimeType(@"Path\To\My\File.docx");
Console.WriteLine(mimeType);
> application/msword
> application/vnd.openxmlformats-officedocument.wordprocessingml.document
FileCategory category = FTT.GetFileCategory(@"Path\To\My\File.docx");
Console.WriteLine(category);
category = FTT.GetFileCategory(@"Path\To\My\File.jpg");
Console.WriteLine(category);
> Document
> Image
string[] extensions = FTT.GetMimeTypeFileExtensions("text/csv");
Console.WriteLine(extensions[0]);
> csv
This library is designed along the following tenets:
- No external dependencies
- No file system access
- Small memory footprint
- Simple static methods (no extension methods and no instantiatable classes)
- Case-insensitive
- Portable - works in applications targeting any CLR
File media types are broken down into relatively few categories. Sub-categories may be considered in a future release according to information on Wikipedia Here are the guidelines that determine a file's category
- Archive: any file that can be extracted into several files
- Audio: any file that can only contain an audio stream
- Binary: any file that is unclassified or does not have a text representation
- Code: any file that contains instructions that are compilable or machine-readable
- Document: any file that is designed for conveying structured information between people
- Image: any file that can only contain a single image or series of images
- PDF: any file that is considered a document archive format
- Presentation: any file that is designed for electronic presentations consisting of a series of separate pages or slides
- Spreadsheet: any file in which data is arranged in rows and columns and can be manipulated and used in calculations
- Text: any file that is not classified under another category and is not binary
- Video: any file that is designed to be a container for a video stream
- Even though a mime type to file extension mapping is not necessarily one-to-one, the most common should be returned by the library
- This library does not provide file sniffing capabilities - in other words, if you have a file and you want to verify the contents are of a specific type, look elsewhere. FTT only uses the file name with an extension. That capability may be added in a future release.
- The only file categories presently considered are Archive, Audio, Binary, Code, Document, Image, PDF, Presentation, Spreadsheet, Text, and Video. Binary is the default if there is no match in the database.
While it is unrealistic to expect this library to provide a comprehensive list with all the file types the world has to offer, it would be nice if we could get close. Generally, if the file type is even remotely common, it is listed in one of the sources. You can submit a bug report for a file type that is missing or that you think should be added. You will have to include a reputable source as well.