deepseek-ai/deepseek-harness · error · UnsupportedImageMediaTypeError

unsupported image media type: ${mediaType || '(empty)'}

Error message

unsupported image media type: ${mediaType || '(empty)'}

What it means

imageMediaType() is the single MIME whitelist for composer images: image/png, image/jpeg, image/webp, image/gif. Any other value — including the empty string, displayed as '(empty)' — throws UnsupportedImageMediaTypeError. It runs inside createDraftImages() before any attachment is registered, and again inside encodeImage() during serialization.

Source

Thrown at packages/client/ui-conversation/src/client/service.ts:358

  /** Canonical base64 wire form of one browser image file. */
  private async encodeImage(file: File): Promise<SubmitImageAttachment> {
    return {
      mediaType: imageMediaType(file.type),
      data: bytesToBase64(new Uint8Array(await file.arrayBuffer())),
      ...(file.name === '' ? {} : { name: file.name }),
    }
  }
}

function imageMediaType(value: string): ImageMediaType {
  switch (value) {
    case 'image/png':
    case 'image/jpeg':
    case 'image/webp':
    case 'image/gif':
      return value
    default:
      throw new UnsupportedImageMediaTypeError(value)
  }
}

function bytesToBase64(data: Uint8Array): string {
  let binary = ''
  const chunk = 0x8000
  for (let offset = 0; offset < data.length; offset += chunk) {
    binary += String.fromCharCode(...data.subarray(offset, offset + chunk))
  }
  return btoa(binary)
}

function revokePreview(url: string): void {
  if (url.startsWith('blob:')) URL.revokeObjectURL(url)
}

View on GitHub (pinned to b150a551b8)

Solutions

  1. Validate file.type against the four accepted MIME values before calling createDraftImages and reject unsupported files with a user notice
  2. Transcode HEIC/AVIF to PNG or JPEG client-side (canvas or codec library) before attaching
  3. Give synthetic Files an explicit accepted MIME type

Example fix

// before
const attachments = service.createDraftImages(files)
// after
const supported = files.filter(f => SUPPORTED_IMAGE_TYPES.has(f.type))
notifySkipped(files.length - supported.length)
const attachments = service.createDraftImages(supported)
Defensive patterns

Strategy: type-guard

Validate before calling

const rejected = files.filter(f => !isSupportedImageType(f))
if (rejected.length > 0) notifyUnsupported(rejected)

Type guard

const SUPPORTED_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])
function isSupportedImageType(file: File): file is File & { type: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' } {
  return SUPPORTED_IMAGE_TYPES.has(file.type)
}

Try / catch

try {
  return service.createDraftImages(files)
} catch (error) {
  if (error instanceof UnsupportedImageMediaTypeError) return rejectWithNotice(files, error)
  throw error
}

Prevention

When it happens

Trigger: Passing a File whose type is image/heic (iPhone photos), image/avif, image/svg+xml, application/octet-stream, or '' (extensionless blobs, synthetic Files built without a MIME type) into createDraftImages(); or feeding such a file to encodeImage().

Common situations: iOS Safari uploads defaulting to HEIC; AVIF exports from modern image tools; dragged-in SVGs; test fixtures constructed as new File([bytes], 'x') with no type option.

Related errors


AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24). Data as JSON: /api/errors/1436c6c3bda95884. Report an issue: GitHub.