{"record":{"id":"2db6b7f364f918fd","repo":"iOfficeAI/OfficeCLI","slug":"unsupported-mime-type-mime-supported-image-pn","errorCode":null,"errorMessage":"Unsupported MIME type: {mime}. Supported: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/svg+xml","messagePattern":"Unsupported MIME type: (.+?)\\. Supported: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/svg\\+xml","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/officecli/Core/ImageSource.cs","lineNumber":189,"sourceCode":"            return (stream, ct);\n\n        // Fallback: extract extension from URL path (strip query string)\n        var uri = new Uri(url);\n        var ext = Path.GetExtension(uri.AbsolutePath);\n        if (!string.IsNullOrEmpty(ext))\n            return (stream, ExtensionToContentType(ext));\n\n        // Last resort: sniff magic bytes\n        if (TrySniffContentType(bytes, out var sniffed))\n            return (stream, sniffed);\n\n        throw new ArgumentException($\"Cannot determine image type from URL: {url}. Specify format via file extension or content-type header.\");\n    }\n\n    private static PartTypeInfo MimeToContentType(string mime)\n    {\n        if (TryMimeToContentType(mime, out var ct)) return ct;\n        throw new ArgumentException($\"Unsupported MIME type: {mime}. Supported: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/svg+xml\");\n    }\n\n    private static bool TryMimeToContentType(string mime, out PartTypeInfo contentType)\n    {\n        contentType = mime.ToLowerInvariant() switch\n        {\n            \"image/png\" => ImagePartType.Png,\n            \"image/jpeg\" or \"image/jpg\" => ImagePartType.Jpeg,\n            \"image/gif\" => ImagePartType.Gif,\n            \"image/bmp\" => ImagePartType.Bmp,\n            \"image/tiff\" or \"image/tif\" => ImagePartType.Tiff,\n            \"image/svg+xml\" => ImagePartType.Svg,\n            \"image/emf\" or \"image/x-emf\" => ImagePartType.Emf,\n            \"image/wmf\" or \"image/x-wmf\" => ImagePartType.Wmf,\n            _ => default\n        };\n        return contentType != default;\n    }","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/iOfficeAI/OfficeCLI/blob/1ced45e900782c5083ed550ddf328ee974e425e7/src/officecli/Core/ImageSource.cs#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"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').","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'."],"exampleFix":"// before — WebP MIME not supported\nadd image src='data:image/webp;base64,UklGRkR...' path='/body'\n\n// after — convert to PNG, use PNG MIME\nadd image src='data:image/png;base64,iVBORw0KGgo...' path='/body'","handlingStrategy":"validation","validationCode":"// Pre-check the MIME type is supported before resolving\nvar supportedMimes = new HashSet<string>(StringComparer.OrdinalIgnoreCase)\n{\n    \"image/png\", \"image/jpeg\", \"image/jpg\", \"image/gif\",\n    \"image/bmp\", \"image/tiff\", \"image/tif\", \"image/svg+xml\",\n    \"image/emf\", \"image/x-emf\", \"image/wmf\", \"image/x-wmf\"\n};\n\nstring mime = ExtractMimeFromDataUri(source); // your helper\nif (!supportedMimes.Contains(mime))\n{\n    Console.Error.WriteLine($\"Unsupported MIME type: {mime}. Convert to a supported format.\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var (stream, contentType) = ImageSource.Resolve(source);\n}\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Unsupported MIME type\"))\n{\n    // Convert the image to png/jpeg and rebuild the data URI\n}","preventionTips":["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."],"tags":["image","mime-type","format-unsupported","data-uri","validation"],"backgroundTag":null,"analyzedSha":"1ced45e900782c5083ed550ddf328ee974e425e7","analyzedAt":"2026-08-13T13:01:07.193Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}