{"record":{"id":"1436c6c3bda95884","repo":"deepseek-ai/deepseek-harness","slug":"unsupported-image-media-type-mediatype-emp","errorCode":null,"errorMessage":"unsupported image media type: ${mediaType || '(empty)'}","messagePattern":"unsupported image media type: (.+?)","errorType":"validation","errorClass":"UnsupportedImageMediaTypeError","httpStatus":null,"severity":"error","filePath":"packages/client/ui-conversation/src/client/service.ts","lineNumber":358,"sourceCode":"  /** Canonical base64 wire form of one browser image file. */\n  private async encodeImage(file: File): Promise<SubmitImageAttachment> {\n    return {\n      mediaType: imageMediaType(file.type),\n      data: bytesToBase64(new Uint8Array(await file.arrayBuffer())),\n      ...(file.name === '' ? {} : { name: file.name }),\n    }\n  }\n}\n\nfunction imageMediaType(value: string): ImageMediaType {\n  switch (value) {\n    case 'image/png':\n    case 'image/jpeg':\n    case 'image/webp':\n    case 'image/gif':\n      return value\n    default:\n      throw new UnsupportedImageMediaTypeError(value)\n  }\n}\n\nfunction bytesToBase64(data: Uint8Array): string {\n  let binary = ''\n  const chunk = 0x8000\n  for (let offset = 0; offset < data.length; offset += chunk) {\n    binary += String.fromCharCode(...data.subarray(offset, offset + chunk))\n  }\n  return btoa(binary)\n}\n\nfunction revokePreview(url: string): void {\n  if (url.startsWith('blob:')) URL.revokeObjectURL(url)\n}\n","sourceCodeStart":340,"sourceCodeEnd":374,"githubUrl":"https://github.com/deepseek-ai/deepseek-harness/blob/b150a551b8d465e31e418e1b2eaf5e79bbb7d28e/packages/client/ui-conversation/src/client/service.ts#L340-L374","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Validate file.type against the four accepted MIME values before calling createDraftImages and reject unsupported files with a user notice","Transcode HEIC/AVIF to PNG or JPEG client-side (canvas or codec library) before attaching","Give synthetic Files an explicit accepted MIME type"],"exampleFix":"// before\nconst attachments = service.createDraftImages(files)\n// after\nconst supported = files.filter(f => SUPPORTED_IMAGE_TYPES.has(f.type))\nnotifySkipped(files.length - supported.length)\nconst attachments = service.createDraftImages(supported)","handlingStrategy":"type-guard","validationCode":"const rejected = files.filter(f => !isSupportedImageType(f))\nif (rejected.length > 0) notifyUnsupported(rejected)","typeGuard":"const SUPPORTED_IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/webp', 'image/gif'])\nfunction isSupportedImageType(file: File): file is File & { type: 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif' } {\n  return SUPPORTED_IMAGE_TYPES.has(file.type)\n}","tryCatchPattern":"try {\n  return service.createDraftImages(files)\n} catch (error) {\n  if (error instanceof UnsupportedImageMediaTypeError) return rejectWithNotice(files, error)\n  throw error\n}","preventionTips":["Filter at the file picker and drop zone, not at submit time","Transcode HEIC and AVIF sources to PNG or JPEG before attaching","Never construct File objects without an explicit accepted MIME type"],"tags":["images","mime-type","validation","file-upload"],"backgroundTag":"unsupported-media-type","analyzedSha":"b150a551b8d465e31e418e1b2eaf5e79bbb7d28e","analyzedAt":"2026-08-24T18:12:29.105Z","schemaVersion":2},"datasetVersion":"2026-08-24T22:17:12.610Z"}