{"record":{"id":"e0291ef1f4ffc267","repo":"spring-projects/spring-ai","slug":"unsupported-media-format","errorCode":null,"errorMessage":"Unsupported media format: ","messagePattern":"Unsupported media format: ","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModel.java","lineNumber":590,"sourceCode":"\t\t\telse {\n\t\t\t\tthrow new IllegalArgumentException(\"Invalid Image content type: \" + media.getData().getClass());\n\t\t\t}\n\n\t\t\treturn ContentBlock.fromImage(ImageBlock.builder()\n\t\t\t\t.source(sourceBuilder.build())\n\t\t\t\t.format(BedrockMediaFormat.getImageFormat(mimeType))\n\t\t\t\t.build());\n\t\t}\n\t\telse if (BedrockMediaFormat.isSupportedDocumentFormat(mimeType)) { // Document\n\n\t\t\treturn ContentBlock.fromDocument(DocumentBlock.builder()\n\t\t\t\t.name(sanitizeDocumentName(media.getName()))\n\t\t\t\t.format(BedrockMediaFormat.getDocumentFormat(mimeType))\n\t\t\t\t.source(DocumentSource.builder().bytes(SdkBytes.fromByteArray(media.getDataAsByteArray())).build())\n\t\t\t\t.build());\n\t\t}\n\n\t\tthrow new IllegalArgumentException(\"Unsupported media format: \" + mimeType);\n\t}\n\n\t/**\n\t * Sanitizes a document name to conform to Amazon Bedrock's naming restrictions. The\n\t * name can only contain alphanumeric characters, whitespace characters (no more than\n\t * one in a row), hyphens, parentheses, and square brackets.\n\t * @param name the document name to sanitize\n\t * @return the sanitized document name\n\t * @see <a href=\n\t * \"https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html\">DocumentBlock\n\t * API Reference</a>\n\t */\n\tstatic String sanitizeDocumentName(String name) {\n\t\treturn name.replaceAll(\"[^a-zA-Z0-9\\\\s\\\\-()\\\\[\\\\]]\", \"-\");\n\t}\n\n\t/**\n\t * Convert {@link ConverseResponse} to {@link ChatResponse} includes model output,","sourceCodeStart":572,"sourceCodeEnd":608,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModel.java#L572-L608","documentation":"Terminal guard in mapMediaToContentBlock: after the document and image branches, if the Media's MIME type matches no supported document or image format, this IllegalArgumentException is thrown. Bedrock only accepts a fixed set of media formats and the library maps MimeType via BedrockMediaFormat.","triggerScenarios":"Passing a Media with a MimeType not in BedrockMediaFormat's image/document maps — e.g. image/svg+xml, image/webp (if unsupported), audio formats, application/pdf以外的 unsupported types — so neither getImageFormat nor getDocumentFormat matches.","commonSituations":"Sending WebP or SVG images to Bedrock (not supported by the Converse API); sending audio files expecting transcription through chat; typos in MimeType like 'image/jpg' instead of 'image/jpeg'.","solutions":["Convert the media to a supported format (png, jpeg, gif, webp per Bedrock docs) before sending.","Use 'image/jpeg' not 'image/jpg'; verify the MimeType constant matches the actual bytes.","Check BedrockMediaFormat's supported format maps to confirm the type before calling.","For documents use supported formats (pdf, csv, doc, docx, xls, xlsx, html, txt, md)."],"exampleFix":"// before\nMedia media = new Media(new MimeType(\"image\", \"svg+xml\"), svgBytes);\n// after\nBufferedImage img = ImageIO.read(/* svg rendered to raster */);\nByteArrayOutputStream out = new ByteArrayOutputStream();\nImageIO.write(img, \"png\", out);\nMedia media = new Media(MimeTypeUtils.IMAGE_PNG, out.toByteArray());","handlingStrategy":"validation","validationCode":"MimeType mt = media.getMimeType();\nif (!BedrockMediaFormat.isSupportedImageFormat(mt) && !BedrockMediaFormat.isSupportedDocumentFormat(mt)) {\n    throw new IllegalArgumentException(\"Unsupported media for Bedrock: \" + mt);\n}","typeGuard":"boolean isBedrockSupportedMedia(MimeType mt) {\n    return Boolean.TRUE.equals(BedrockMediaFormat.isSupportedImageFormat(mt))\n        || Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mt));\n}","tryCatchPattern":"try {\n    model.call(prompt);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unsupported media format\")) {\n        // convert to PNG/JPEG/PDF and retry\n    } else throw e;\n}","preventionTips":["Use image/png or image/jpeg for images; image/jpg is invalid","Convert WebP/SVG/AVIF to PNG/JPEG before sending","Restrict uploads at your API boundary to Bedrock-supported MIME types","Verify MimeType matches the actual byte content"],"tags":["media","unsupported-format","mime-type","bedrock"],"backgroundTag":"unsupported-enum-value","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}