Skip to content

[API Proposal]: Add Common Video Types to System.Net.Mime.MediaTypeNames #124392

@Cryptoc1

Description

@Cryptoc1

Background and motivation

Currently, MediaTypeNames provides various sub-classes for varying content types, e.g. Application, Image, Text, etc. A Video sub-class should be added to provide constants for common/popular video types used across [web] applications.

API Proposal

namespace System.Net.Mime;

public static class MediaTypeNames
{
    // ...

    /// <summary>Specifies the kind of video data in an email message attachment.</summary>
        public static class Video
        {
            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in AV1 format.</summary>
            public const string Av1 = "video/av1";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in H.264 format.</summary>
            public const string H264 = "video/h264";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in H.265 format.</summary>
            public const string H265 = "video/h265";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in Matroska format.</summary>
            public const string Matroska = "video/matroska";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in MP4 format.</summary>
            public const string Mp4 = "video/mp4";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in MPEG format.</summary>
            public const string Mpeg = "video/mpeg";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in MPV format.</summary>
            public const string Mpv = "video/mpv";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in Ogg format.</summary>
            public const string Ogg = "video/ogg";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in Quicktime format.</summary>
            public const string QuickTime = "video/quicktime";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in VP8 format.</summary>
            public const string Vp8 = "video/vp8";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in VP9 format.</summary>
            public const string Vp9 = "video/vp9";

            /// <summary>Specifies that the <see cref="MediaTypeNames.Video"/> data is in WebM format.</summary>
            public const string Webm = "video/webm";
        }

    // ...
}

API Usage

public static async Task<Results<Created, ValidationProblem>> UploadVideo([FromForm] IFormFile file)
{
    if( file.ContentType is not MediaTypeNames.Video.Mp4 )
    {
        return TypedResults.ValidationProblem( new Dictionary<string, string[]>
        {
            { nameof(file), [$"{nameof(file)} must be a mp4 video."] }
        } );
    }

    // ...
}

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionEarly API idea and discussion, it is NOT ready for implementationarea-System.Net

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions