jellyfin/jellyfin · error · ArgumentException

Unable to determine image file extension from mime type {0}

Error message

Unable to determine image file extension from mime type {0}

What it means

ImageSaver.GetStandardSavePath throws when MimeTypes.ToExtension(mimeType) returns null/whitespace, i.e. the mime type is not in the extension lookup. ToExtension strips parameters (charset), checks the lookup table, then falls back to GetMimeTypeExtensions; if both miss it returns null and saving cannot pick a file extension.

Source

Thrown at MediaBrowser.Providers/Manager/ImageSaver.cs:403

        /// <param name="item">The item.</param>
        /// <param name="type">The type.</param>
        /// <param name="imageIndex">Index of the image.</param>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <param name="saveLocally">if set to <c>true</c> [save locally].</param>
        /// <returns>System.String.</returns>
        /// <exception cref="ArgumentNullException">
        /// imageIndex
        /// or
        /// imageIndex.
        /// </exception>
        private string GetStandardSavePath(BaseItem item, ImageType type, int? imageIndex, string mimeType, bool saveLocally)
        {
            var season = item as Season;
            var extension = MimeTypes.ToExtension(mimeType);

            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Unable to determine image file extension from mime type {0}", mimeType));
            }

            if (string.Equals(extension, ".jpeg", StringComparison.OrdinalIgnoreCase))
            {
                extension = ".jpg";
            }

            extension = extension.ToLowerInvariant();

            if (type == ImageType.Primary && saveLocally)
            {
                if (season is not null && season.IndexNumber.HasValue)
                {
                    var seriesFolder = season.SeriesPath;

                    var seasonMarker = season.IndexNumber.Value == 0
                                           ? "-specials"
                                           : season.IndexNumber.Value.ToString("00", CultureInfo.InvariantCulture);

View on GitHub (pinned to ae8723026d)

Solutions

  1. Normalize the mime type to a supported one before saving (e.g. map image/avif -> image/jpeg or register an extension mapping).
  2. Register the mime->extension pair in MimeTypes extensions if the format is genuinely supported by SkiaSharp.
  3. Catch ArgumentException at the save call site and skip/preserve the existing image.
  4. Validate mimeType with !string.IsNullOrWhiteSpace(MimeTypes.ToExtension(mimeType)) before attempting to save.

Example fix

// before
var extension = MimeTypes.ToExtension(mimeType);
if (string.IsNullOrWhiteSpace(extension))
    throw new ArgumentException(...);

// after
var extension = MimeTypes.ToExtension(mimeType);
if (string.IsNullOrWhiteSpace(extension))
{
    _logger.LogWarning("Unknown image mime {Mime}, skipping save", mimeType);
    return;
}
Defensive patterns

Strategy: validation

Validate before calling

var ext = MimeTypes.ToExtension(mimeType);
if (string.IsNullOrWhiteSpace(ext))
{
    _logger.LogWarning("Unknown image mime {Mime}", mimeType);
    return; // skip save
}

Type guard

static bool HasKnownImageExtension(string mime) =>
    !string.IsNullOrWhiteSpace(MimeTypes.ToExtension(mime));

Try / catch

try { path = GetStandardSavePath(item, type, idx, mime, saveLocally); }
catch (ArgumentException ex) { _logger.LogWarning(ex.Message); return; }

Prevention

When it happens

Trigger: Saving an image whose mime type is unrecognized (e.g. "image/avif", "image/heic", "application/octet-stream" with no path fallback, or an exotic vendor mime type).

Common situations: A metadata provider returning an unusual image mime type; an avif/heic cover from a newer scraper; a provider reporting a generic mime that ToExtension cannot map.

Related errors


AI-assisted analysis of jellyfin/jellyfin@ae8723026d (2026-08-13). Data as JSON: /api/errors/e559bc72ee4951cc. Report an issue: GitHub.