fix: guess mimeType when uri is DataURI and mimeType is empty

This commit is contained in:
amamagi 2025-11-25 17:12:54 +09:00
parent e7e494f5a9
commit 7e482e1bfe

View File

@ -397,6 +397,24 @@ namespace UniGLTF
{
return null;
}
// for Data URI
if (uri.StartsWith("data:", StringComparison.Ordinal))
{
var headerEnd = uri.IndexOf(',');
if (headerEnd < 0)
{
return null;
}
const int dataPrefixLength = 5; // "data:".Length
var header = uri[dataPrefixLength..headerEnd];
var semicolonPos = header.IndexOf(';');
var mime = semicolonPos >= 0 ? header[..semicolonPos] : header;
return mime is "image/png" or "image/jpeg" ? mime : null;
}
var ext = System.IO.Path.GetExtension(uri).ToLowerInvariant();
switch (ext)
{