iOfficeAI/OfficeCLI · error · ArgumentException
Unsupported MIME type: {mime}. Supported: image/png, image/j
Error message
Unsupported MIME type: {mime}. Supported: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/svg+xml What it means
Thrown by ImageSource.MimeToContentType (a private helper called from ResolveDataUri and indirectly from ResolveUrl) when a MIME type string doesn't match any of the supported image MIME types. The supported set is: image/png, image/jpeg (or image/jpg), image/gif, image/bmp, image/tiff (or image/tif), image/svg+xml, image/emf (or image/x-emf), image/wmf (or image/x-wmf). Any other MIME type triggers this error. Unlike TryMimeToContentType which returns false gracefully, MimeToContentType throws.
Source
Thrown at src/officecli/Core/ImageSource.cs:189
return (stream, ct);
// Fallback: extract extension from URL path (strip query string)
var uri = new Uri(url);
var ext = Path.GetExtension(uri.AbsolutePath);
if (!string.IsNullOrEmpty(ext))
return (stream, ExtensionToContentType(ext));
// Last resort: sniff magic bytes
if (TrySniffContentType(bytes, out var sniffed))
return (stream, sniffed);
throw new ArgumentException($"Cannot determine image type from URL: {url}. Specify format via file extension or content-type header.");
}
private static PartTypeInfo MimeToContentType(string mime)
{
if (TryMimeToContentType(mime, out var ct)) return ct;
throw new ArgumentException($"Unsupported MIME type: {mime}. Supported: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/svg+xml");
}
private static bool TryMimeToContentType(string mime, out PartTypeInfo contentType)
{
contentType = mime.ToLowerInvariant() switch
{
"image/png" => ImagePartType.Png,
"image/jpeg" or "image/jpg" => ImagePartType.Jpeg,
"image/gif" => ImagePartType.Gif,
"image/bmp" => ImagePartType.Bmp,
"image/tiff" or "image/tif" => ImagePartType.Tiff,
"image/svg+xml" => ImagePartType.Svg,
"image/emf" or "image/x-emf" => ImagePartType.Emf,
"image/wmf" or "image/x-wmf" => ImagePartType.Wmf,
_ => default
};
return contentType != default;
}View on GitHub (pinned to 1ced45e900)
Solutions
- Convert the image to a supported format (png, jpeg, gif, bmp, tiff, svg) before creating the data URI.
- If the MIME type is a variant of a supported format, use the canonical form (e.g. 'image/jpeg' not 'image/jpegn').
- For EMF/WMF, use the MIME types 'image/emf'/'image/x-emf' or 'image/wmf'/'image/x-wmf'.
Example fix
// before — WebP MIME not supported add image src='data:image/webp;base64,UklGRkR...' path='/body' // after — convert to PNG, use PNG MIME add image src='data:image/png;base64,iVBORw0KGgo...' path='/body'
Defensive patterns
Strategy: validation
Validate before calling
// Pre-check the MIME type is supported before resolving
var supportedMimes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"image/png", "image/jpeg", "image/jpg", "image/gif",
"image/bmp", "image/tiff", "image/tif", "image/svg+xml",
"image/emf", "image/x-emf", "image/wmf", "image/x-wmf"
};
string mime = ExtractMimeFromDataUri(source); // your helper
if (!supportedMimes.Contains(mime))
{
Console.Error.WriteLine($"Unsupported MIME type: {mime}. Convert to a supported format.");
return;
} Try / catch
try
{
var (stream, contentType) = ImageSource.Resolve(source);
}
catch (ArgumentException ex) when (ex.Message.Contains("Unsupported MIME type"))
{
// Convert the image to png/jpeg and rebuild the data URI
} Prevention
- Convert images to standard formats (png, jpeg) before creating data URIs.
- Validate the MIME type in the data URI header against the supported set before embedding.
- Avoid uncommon or vendor-specific MIME types for embedded images.
When it happens
Trigger: Passing a data URI with an unsupported MIME type like 'data:image/webp;base64,...'. When ResolveDataUri extracts the MIME from the header and calls MimeToContentType which throws for unrecognized types. When ResolveUrl reads a server Content-Type of 'image/heic' and TryMimeToContentType returns false, but the caller uses the throwing variant.
Common situations: A data URI generated from a WebP, HEIC, AVIF, or ICO image — formats not in the supported set. A server that reports an uncommon or vendor-specific MIME type for a standard image. A user who hand-crafted a data URI with a typo in the MIME type (e.g. 'image/jpegn').
Related errors
- Invalid data URI: missing comma separator
- Only base64-encoded data URIs are supported
- Invalid data URI: empty base64 payload (would produce a 0-by
- Invalid data URI: missing comma separator
- Only base64-encoded data URIs are supported
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/2db6b7f364f918fd.
Report an issue: GitHub.