dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15k stars 4.67k forks source link

System.Net.Mime.MediaTypeNames missing types #1489

Closed snebjorn closed 1 year ago

snebjorn commented 6 years ago

https://github.com/dotnet/corefx/blob/3f0bd5d8c3d019ad8b1561395030a58bc38ddfe9/src/System.Net.Mail/ref/System.Net.Mime.cs#L44

I tried using System.Net.Mime.MediaTypeNames in my asp net core api to remove "magic strings"

[Consumes(System.Net.Mime.MediaTypeNames.Application...)]
public IActionResult Post(...)
{ ... }

But it's missing quite a few MIME types.

These come to mind:

text/css text/javascript

application/json application/json-patch+json application/xml application/javascript application/x-www-form-urlencoded

multipart/form-data multipart/byteranges

image/png image/bmp image/webp image/svg+xml

audio/midi audio/mpeg audio/webm audio/ogg audio/wav

video/webm video/ogg

weitzhandler commented 6 years ago

Please implement this already!

See this and this.

gtaylor1981 commented 6 years ago

See dotnet/corefx#26201 for application/json and application/xml

sven5 commented 6 years ago

I'm currently dealing with file uploads. It would be great to have MIME types for Office documents (Word, Excel).

snebjorn commented 6 years ago

Perhaps System.Net.Mime.MediaTypeNames will share the same fate as System.Net.HttpStatusCode. Which is that it's considered dead and not to be used.

https://github.com/aspnet/Mvc/issues/6997#issuecomment-384439229

coldacid commented 5 years ago

Perhaps System.Net.Mime.MediaTypeNames will share the same fate as System.Net.HttpStatusCode. Which is that it's considered dead and not to be used.

aspnet/Mvc#6997 (comment)

Funny that MediaTypeNames or at least its inner classes are designed more or less the same as StatusCodes, the replacement for HttpStatusCode.

GF-Huang commented 5 years ago

2019 still no application/x-www-form-urlencoded.

hezymal commented 5 years ago

Maybe class MediaTypeNames and nested classes as partial?

coldacid commented 5 years ago

I don't think you can spread a partial type across multiple assemblies.

CleytonGoncalves commented 5 years ago

This issue has been marked as up-for-grabs, but we still need to wait for the API approval, is that correct?

danmoseley commented 5 years ago

It's public API so strictly, yes (not sure whether https://github.com/dotnet/corefx/pull/36365 got API approval). @wfurt can share how to best do that eg with a PR.

wfurt commented 5 years ago

Let me ask around @danmosemsft. The list here seems more reasonable than dotnet/corefx#36365.

karelz commented 4 years ago

Triage: We are open to add a few of the MIME type enums. Next step: Create proposal with most used ones (with some links to usage ideally) and with names how they should be exposed.

weitzhandler commented 4 years ago

BTW might of interest to subscribers: https://github.com/dotnet/csharplang/issues/2849

ahordijk commented 4 years ago

With problemdetails, https://tools.ietf.org/html/rfc7807, implemented in .net core please add:

douglasg14b commented 4 years ago

@karelz Is there a specific format example you have in mind for this proposal? What restrictions and limitations should someone interested in making a pull request be aware of?

karelz commented 4 years ago

PR is early. We need API proposal first, well thought through as suggested above: https://github.com/dotnet/runtime/issues/1489#issuecomment-537625716 The API proposal info is here: https://github.com/dotnet/runtime/blob/main/docs/project/api-review-process.md with good examples in form. Usage data will be key in this one (does not have examples in linked process)

alexandra142 commented 4 years ago

Hello could you please add "application/merge-patch+json" ?

rjperes commented 3 years ago

Hi, this seems to be a very simple change, doesn't break anything and adds useful MIME types. Why can't we get this to move forward?

karelz commented 3 years ago

@rjperes see the above discussion: https://github.com/dotnet/runtime/issues/1489#issuecomment-541385535

Bilal-io commented 3 years ago

@karelz I am looking at the API review process you linked above, which step did this issue reach? Step one is someone creating an issue (this issue), step two is for the team to assign an owner, why hasn't that happened yet?

Here is my proposal for the common mime types that I believe should exist under the System.Net.Mime.MediaTypeNames namespace. I have checked the existing ones in the list below. I also went with the assumption that mime types of executable files will not be added, is that fair? Maybe not.

Proposal

System.Net.Mime.MediaTypeNames.Text

System.Net.Mime.MediaTypeNames.Application

System.Net.Mime.MediaTypeNames.Image

Additional Categories

System.Net.Mime.MediaTypeNames.Multipart

System.Net.Mime.MediaTypeNames.Font

System.Net.Mime.MediaTypeNames.Video

System.Net.Mime.MediaTypeNames.Audio

Sourced from IANA - Media Types with the help of Mozilla to pick some common mime types.

If I have missed anything that you believe is useful, add it in a comment.

karelz commented 3 years ago

@Bilal-io thanks for your proposal with names! Were you able to get some information about the usage of each of them? (as mentioned above - https://github.com/dotnet/runtime/issues/1489#issuecomment-541385535 https://github.com/dotnet/runtime/issues/1489#issuecomment-537625716) I have to admit some of these are not known to me. For some I would expect they are on decline these days (e.g. Midi?) ... some usage data would make decisions here easier.

Regarding your question:

step two is for the team to assign an owner, why hasn't that happened yet?

You are right that we deviate from the process a bit -- unless the API is super-active, we consider the area owners to be the owners (though not assigned explicitly). In case of Networking area, it is the members of our Networking team (incl. myself). Once API is ready, we discuss proposals in our team meeting to get more thoughts before marking it ready for API review. Also note that in principal we try to not assign issues unless someone works on them actively (otherwise we would be back in place where people had hundred and more issues assigned to them -- which made assignments useless). Hopefully that makes sense ...

snebjorn commented 3 years ago

Unable to find any usage data for MIME types. However Mozilla have a list of Common MIME types.

markwhitaker commented 3 years ago

If it's useful as a workaround, I've implemented lots of missing MIME types in a very lightweight NuGet package (NuGet, source). (An older version is also available as an MIT-licensed gist).

Marusyk commented 3 years ago

I need text/csv )) Any plans?

flimtix commented 2 years ago

This error has been open since 2017. It's such a small thing to add these guys. When will PNG come?

Moreover, @Bilal-io's list is no longer correct.... See this for an updatet version.

oobayly commented 2 years ago

I find it rather strange that the dotnet team are still insisting on collecting usage information in order to add something like image/png.

image

flimtix commented 2 years ago

I find it rather strange that the dotnet team are still insisting on collecting usage information... @oobayly

As long as the MIME type does not exist, you cannot increase the number of usage... Genius idea! 😂

AraHaan commented 2 years ago

It's also missing the csv media type name as well.

bgilner-rgg commented 2 years ago

text/json text/x-json text/javascript

AraHaan commented 2 years ago

application/zlib-stream

jacrys commented 2 years ago

text/json text/x-json text/javascript

json isn't a text MIME type, it is an application type and is already in the API at MediaTypeNames.Application.Json. (Source: RFC 4627 & .NET 6 Docs)

text/x-json was never ratified, nor was text/javascript.

ldeluigi commented 1 year ago

Please add text/csv too. This issue is from 2017

mmarinchenko commented 1 year ago

https://github.com/dotnet/runtime/issues/1489#issuecomment-537625716

Triage: We are open to add a few of the MIME type enums. Next step: Create proposal with most used ones (with some links to usage ideally) and with names how they should be exposed.

@karelz I can agree that the audio, video, and office mime types have special uses and are not found in every application. But can we start with the file types used in the ASP.NET Core project templates, with the addition of related and some other well-known formats? I found most of the font and image formats there in the wwwroot directories.

Additional sources are: IANA Media Types and ASP.NET Core FileExtensionContentTypeProvider.

The Proposal

Application

Font

Image

Multipart

Text

wfurt commented 1 year ago

The proposed list above seems quite reasonable. I can try to take it through API review @karelz. While I personally see the benefit small, the effort is also somewhat small and we get help from the community.

karelz commented 1 year ago

@wfurt yeah, if you can bring it to Networking meeting first, let's check that we have "reasonability" agreement. Then we can push it through API review. Thanks for help!

karelz commented 1 year ago

Triage: The team discussed it on Thu 3/16. There was general agreement with the latest proposal - thank you @mmarinchenko! @wfurt will update the proposal into form ready for API review and mark it as such. We should be able to get it into 8.0 without any troubles.

AraHaan commented 1 year ago

Triage: The team discussed it on Thu 3/16. There was general agreement with the latest proposal - thank you @mmarinchenko! @wfurt will update the proposal into form ready for API review and mark it as such. We should be able to get it into 8.0 without any troubles.

Will this include adding zlib-stream to the class as ZlibStream (to let the people know to use the ZlibStream class in .NET to decompress the stream data)?

wfurt commented 1 year ago

I was not planning to @AraHaan. Do you have example of public sites using it or is that something you applications do internally? https://www.rfc-editor.org/rfc/rfc6713 shows application/zlib and application/gzip so I'm note sure from where the -stream is coming. The mime type should be specific to the content not the implementation producing it, right?

AraHaan commented 1 year ago

I am not sure, it might have been a random case where I noticed an zlib-stream version of it.