{"record":{"id":"9bc93f3ed3ae2d75","repo":"can1357/oh-my-pi","slug":"unknown-image-type-mimetype","errorCode":null,"errorMessage":"Unknown image type: ${mimeType}","messagePattern":"Unknown image type: (.+?)","errorType":"validation","errorClass":"ValidationError","httpStatus":null,"severity":"error","filePath":"packages/ai/src/providers/amazon-bedrock.ts","lineNumber":1148,"sourceCode":" */\nfunction createImageBlock(mimeType: string, data: string): ImageBlockWire[\"image\"] {\n\tlet format: \"jpeg\" | \"png\" | \"gif\" | \"webp\";\n\tswitch (mimeType) {\n\t\tcase \"image/jpeg\":\n\t\tcase \"image/jpg\":\n\t\t\tformat = \"jpeg\";\n\t\t\tbreak;\n\t\tcase \"image/png\":\n\t\t\tformat = \"png\";\n\t\t\tbreak;\n\t\tcase \"image/gif\":\n\t\t\tformat = \"gif\";\n\t\t\tbreak;\n\t\tcase \"image/webp\":\n\t\t\tformat = \"webp\";\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new AIError.ValidationError(`Unknown image type: ${mimeType}`);\n\t}\n\treturn { source: { bytes: data }, format };\n}\n","sourceCodeStart":1130,"sourceCodeEnd":1152,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/ai/src/providers/amazon-bedrock.ts#L1130-L1152","documentation":"createImageBlock maps an image MIME type to one of the four formats Bedrock's Converse API accepts: jpeg, png, gif, webp. Any other MIME type hits the default branch and throws a ValidationError naming the offending type. Bedrock simply has no wire representation for other image formats, so the library fails fast client-side.","triggerScenarios":"Passing an ImageBlock with a mimeType outside {image/jpeg, image/jpg, image/png, image/gif, image/webp} — e.g. image/svg+xml, image/tiff, image/avif, image/heic — to a Bedrock request.","commonSituations":"Feeding screenshots from tools that emit WebP variants is fine, but HEIC photos from iOS devices, SVG assets, or AVIF images from modern web pipelines are not; file-upload features trusting the client-declared Content-Type.","solutions":["Convert the image to PNG or JPEG before sending (e.g. with sharp: sharp(input).png().toBuffer())","If the source is SVG or vector, rasterize it to PNG first — Bedrock cannot ingest vector formats","Validate the MIME type at ingestion time (sniff magic bytes, not just the declared type) and reject/convert unsupported formats early","For HEIC (iPhone photos), transcode to JPEG before adding the image block"],"exampleFix":"// before\nblocks.push({ type: \"image\", mimeType: \"image/heic\", data: heicBase64 });\n// after: convert first\nconst png = await sharp(Buffer.from(heicBase64, \"base64\")).png().toBuffer();\nblocks.push({ type: \"image\", mimeType: \"image/png\", data: png.toString(\"base64\") });","handlingStrategy":"validation","validationCode":"const BEDROCK_IMAGE_TYPES = new Set([\"image/jpeg\", \"image/jpg\", \"image/png\", \"image/gif\", \"image/webp\"]);\nfunction assertBedrockImage(block: ImageBlock): void {\n  if (!BEDROCK_IMAGE_TYPES.has(block.mimeType)) {\n    throw new Error(`Convert ${block.mimeType} to png/jpeg before sending to Bedrock`);\n  }\n}","typeGuard":"function isBedrockSupportedImage(mimeType: string): boolean {\n  return /^image\\/(jpeg|jpg|png|gif|webp)$/.test(mimeType);\n}","tryCatchPattern":"try {\n  await provider.stream(context);\n} catch (err) {\n  if (err instanceof AIError.ValidationError && err.message.startsWith(\"Unknown image type:\")) {\n    const mime = err.message.split(\": \")[1];\n    // convert via sharp and retry once\n    return provider.stream(await convertImages(context, mime));\n  }\n  throw err;\n}","preventionTips":["Normalize all uploaded images to PNG or JPEG at ingestion time","Sniff magic bytes rather than trusting declared Content-Type","Transcode HEIC (iOS) and AVIF sources up front; rasterize SVG before sending"],"tags":["bedrock","validation","image","mime-type"],"backgroundTag":"unsupported-image-format","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}