Giter VIP home page Giter VIP logo

mimemapping's Introduction

MimeMapping

Nuget Nuget build codecov

Constants for (almost) all MIME types and method to determine MIME type from a file name. Contains just over 1000 mime types.

The Dictionary is generated from the jshttp/mime-db db.json. Works similar to .NET's System.Web.MimeMapping.GetMimeMapping.

It aggregates data from the following sources:

The library is just a literal C# Dictionary<string, string> with over 1000 entries, and a helper method that can be passed a file path.

Example Usage

string myFile = "myimage.jpg";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(myFile);
Console.WriteLine(mimeType); // output: image/jpeg

string randomFile = "data.asdf";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(randomFile);
Console.WriteLine(mimeType); // output: application/octet-stream

string rawExtension = "json";
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(rawExtension);
Console.WriteLine(mimeType); // output: application/json


// List all types..
foreach(var kp in MimeMapping.MimeTypes.TypeMap)
{
  Console.WriteLine($"File extension: {kp.Key}, mime string: {kp.Value}");
}

mimemapping's People

Contributors

boychenko avatar coderrob avatar gintsk avatar phxnsharp avatar renovate[bot] avatar theaifam5 avatar tstojecki avatar viceice avatar zone117x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

mimemapping's Issues

Apache mime type list seems outdated. Why don't build this library on iana list?

I notice I bring an example: I verified that sqlite is not even mentioned in the apache list. Moreover "recently" iana has changed the standard (https://stackoverflow.com/a/55071463) and has updated its list accordingly.

I understand that iana doesn't provide the list of extensions together with the mime, but at least you could be able to validate the mime type. So at least you could put this list next to the one used with the file extension.

What is your opinion about this?

thanks

Update repo settings

  • disable merge commits
  • set squash merge to title and commit details
  • enable auto delete branches

๐Ÿค—

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

github-actions
.github/workflows/build.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v4.0.1@ab5e6d0c87105b4c9c2047343972218f562e4319
  • codecov/codecov-action v4.1.0@54bcd8715eee62d40e33596ef5e8f0f48dbbccab
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v4.0.1@ab5e6d0c87105b4c9c2047343972218f562e4319
  • actions/upload-artifact v4.3.1@5d5d22a31266ced268874388b861e4b58bb5c2f3
.github/workflows/release.yml
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • actions/cache v4.0.1@ab5e6d0c87105b4c9c2047343972218f562e4319
  • actions/upload-artifact v4.3.1@5d5d22a31266ced268874388b861e4b58bb5c2f3
  • actions/checkout v4.1.1@b4ffde65f46336ab88eb53be808477a3936bae11
  • tj-actions/git-cliff v1.5.0@75599f745633e29f99bd9e14a30865b7d2fcbe84
  • ncipollo/release-action v1.14.0@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5
nuget
MimeMapping.csproj
  • MinVer 4.3.0
  • Microsoft.SourceLink.GitHub 8.0.0
Test/Test.csproj
  • System.Net.Http 4.3.4
  • Newtonsoft.Json 13.0.3
  • MSTest.TestFramework 3.2.2
  • MSTest.TestAdapter 3.2.2
  • Microsoft.NET.Test.Sdk 17.9.0
regex
KnownMimeTypes.tt
  • mime-db v1.52.0

  • Check this box to trigger a request for Renovate to run again on this repository

GetMimeMapping function is file extension case sensitive

MimeMapping.MimeUtility.GetMimeMapping(mediaFile.Path) function returns "application/octet-stream" for "1.JPG" and "1.Jpg"

Is it a bug or planned behavior?
I'm suggesting to lower case file extension before lookup if that is the bug. And update readme if that is planned behavior.

Refine the build targets

Looking on our build targets it looks like:
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>

Can we drop net461 as it is out-of-support?
Should it be replaced by net462 or can we just trim it? Are we using something useful from it?

Enable renovate bot

@zone117x Can you please enable renovate on this repo. So we get automated dependency updates. I'm a maintainer of that bot, so will configure it for our needs. ๐Ÿค—

Restructure repo

We should restructure repo to a more conventional dotnet project

  • add main project to MimeMapping folder
  • move projects to src and test folders ?
  • others ?

New Release

@zone117x Should we release a major or minor update?

I would prefer a major bump because of the new mime db source and a lot changes because of it.

Example usage invalid

string myFile = "myimage.jpg";
-string mimeType = MimeMapping.MimeTypes.GetMimeMapping(myFile);
+string mimeType = MimeMapping.MimeUtility.GetMimeMapping(myFile);
Console.WriteLine(mimeType); // output: image/jpeg

string randomFile = "data.asdf";
-string mimeType = MimeMapping.MimeTypes.GetMimeMapping(randomFile);
+string mimeType = MimeMapping.MimeUtility.GetMimeMapping(randomFile);
Console.WriteLine(mimeType); // output: application/octet-stream

string rawExtension = "json";
-string mimeType = MimeMapping.MimeTypes.GetMimeMapping(rawExtension);
+string mimeType = MimeMapping.MimeUtility.GetMimeMapping(rawExtension);
Console.WriteLine(mimeType); // output: application/json


// List all types..
foreach(var kp in MimeMapping.MimeTypes.TypeMap)
{
	Console.WriteLine($"File extension: {kp.Key}, mime string: {kp.Value}");
}

Add strong name

Currently given library is missing a strong name signing and hence it cannot be referenced from strongly named libraries and projects. Currently, on build one gets warning:

Warning CS8002 Referenced assembly 'MimeMapping, Version=1.0.1.26, Culture=neutral, PublicKeyToken=null' does not have a strong name.

.. and in runtime this would fail with exception:

Could not load file or assembly 'MimeMapping, Version=1.0.1.26, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)":"MimeMapping, Version=1.0.1.26, Culture=neutral, PublicKeyToken=null

Adding a strong name (with open key) would make the library usable for both signed and unsigned consumers.

Difference with System.Web.MimeMapping.GetMimeMapping

I know the following example uses URL instead of file system path but it works well for System.Web.MimeMapping

var myFile= "https://test.com/file/random-file"
string mimeType = System.Web.MimeMapping.GetMimeMapping(myFile)
//Console.WriteLine(mimeType); // output: application/octet-stream

var myFile= "https://test.com/file/random-file"
string mimeType = MimeMapping.MimeUtility.GetMimeMapping(myFile); //System.ArgumentOutOfRangeException exception

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.