Skip to content

MediaTypes

Namespace: Vercel.AI.ProviderUtils

public static class MediaTypes

Detects IANA media types from file signatures. Maps to detectMediaType.

Inheritance: object

View source

public const int MaxId3TagBytes = 131072

Largest ID3v2 tag skipped before the audio frame.

Value: int

View source

public static string? DetectMediaType(byte[] data, string? topLevelType = null)

Detects a media type from raw bytes or a base64 string. When <code class=“paramref”>topLevelType</code> is omitted, image, document, audio, and video signatures are considered.

Parameters

Name Type Description
data byte[]
topLevelType string

Returns: string

View source

public static string? DetectMediaType(string base64, string? topLevelType = null)

Detects a media type from a base64 string. See String).

Parameters

Name Type Description
base64 string
topLevelType string

Returns: string

View source

public static string GetTopLevelMediaType(string mediaType)

Returns the segment before the first slash. Maps to getTopLevelMediaType.

Parameters

Name Type Description
mediaType string

Returns: string

View source

public static bool IsFullMediaType(string mediaType)

True for type/subtype when the subtype is non-empty and not *. Maps to isFullMediaType.

Parameters

Name Type Description
mediaType string

Returns: bool

View source

public static string ResolveFullMediaType(string mediaType, byte[]? inlineData)

Resolves a media type for inline bytes, or null when the file is not inline. See ResolveFullMediaType(LanguageModelFilePart).

Parameters

Name Type Description
mediaType string
inlineData byte[]

Returns: string

View source

ResolveFullMediaType(LanguageModelFilePart)

Section titled “ResolveFullMediaType(LanguageModelFilePart)”
public static string ResolveFullMediaType(LanguageModelFilePart file)

Returns the file part media type when it has a subtype. Otherwise detects the subtype from the file part data, which is the file part’s bytes or base64 text, or null when the file is not inline. Maps to resolveFullMediaType.

Parameters

Name Type Description
file LanguageModelFilePart

Returns: string

Exceptions

Type Condition
UnsupportedFunctionalityException The subtype cannot be resolved.

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product