MediaTypes
Namespace: Vercel.AI.ProviderUtils
public static class MediaTypesDetects IANA media types from file signatures. Maps to detectMediaType.
Inheritance: object
Fields
Section titled “Fields”MaxId3TagBytes
Section titled “MaxId3TagBytes”public const int MaxId3TagBytes = 131072Largest ID3v2 tag skipped before the audio frame.
Value: int
Methods
Section titled “Methods”DetectMediaType(byte[], string?)
Section titled “DetectMediaType(byte[], string?)”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
DetectMediaType(string, string?)
Section titled “DetectMediaType(string, string?)”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
GetTopLevelMediaType(string)
Section titled “GetTopLevelMediaType(string)”public static string GetTopLevelMediaType(string mediaType)Returns the segment before the first slash. Maps to getTopLevelMediaType.
Parameters
| Name | Type | Description |
|---|---|---|
mediaType |
string |
Returns: string
IsFullMediaType(string)
Section titled “IsFullMediaType(string)”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
ResolveFullMediaType(string, byte[]?)
Section titled “ResolveFullMediaType(string, byte[]?)”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
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. |
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product