Giter Site home page Giter Site logo

mimetypemap's Introduction

MimeTypeMap

FOSSA Status

Summary

Provides a huge two-way mapping of file extensions to mime types and mime types to file extensions, e.g.:

...
{".jpe", "image/jpeg"},
{".jpeg", "image/jpeg"},
{".jpg", "image/jpeg"},
{".js", "application/javascript"},
{".json", "application/json"},
...

Most mime types that have multiple possible extensions are pre-defined to get the most common extension when looking up extension by mime type. Since multiple extensions can map to the same mime type, it is not necessary that GetExtension(GetMimeType(ext)) returns the original extension - it will return the most common extension.

Installation

A NuGet package is available for easy integration into VisualStudio and automatic updates. Alternatively, you can clone and reference or copy the class to your project.

Originally posted on StackOverflow here: http://stackoverflow.com/questions/1029740/get-mime-type-from-filename-extension

Collaboration

Please submit pull requests for any additions. Thanks!

Sam

Usage

After installation MimeTypeMap, include the following using statement in your class:

using MimeTypes;

Getting the mime type to an extension

Console.WriteLine("txt -> " + MimeTypeMap.GetMimeType("txt"));  // "text/plain"

Pass in a string extension and get a mime type back. Optionally include the period. If not it will be added before looking up the mime type.

If no mime type is found then the generic "application/octet-stream" is returned.

Getting the extension to a mime type

Console.WriteLine("audio/wav -> " + MimeTypeMap.GetExtension("audio/wav")); // ".wav"

Pass in a mime type and get an extension back. If the mime type is not registered, an error is thrown.

Changelog

2.3.2.0 - December, 28 2017 - Add Support for .NET Standard 2.0 and .NET Core 2.0

2.1.0 - August 14, 2015 - Refactor and add GetExtension method.

1.2.0 - April 22, 2015 - Breaking changes due to refactorings. You'll need to change namespace after this update. Also added OpenOffice related mime types, in a few cases overwriting rarely used MS mime types for the same extensions.

1.1.0 - April 22, 2015 - Merge pull requests

1.0.0 - Original load from StackOverflow as is

License

FOSSA Status

mimetypemap's People

Contributors

0x1f9f1 avatar axeluser avatar bjarmuz avatar christianackman avatar davebrothers avatar dubrowgn avatar ezelargo avatar fossabot avatar hugohilario avatar illfang avatar jimismith avatar jorrit avatar lettucebo avatar pekkanikander avatar rookev avatar samuelneff avatar tsauvajon avatar william-gross avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.