{"record":{"id":"7d3fc3df5d8db2d6","repo":"spring-projects/spring-ai","slug":"unsupported-media-format-7d3fc3","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/api/BedrockMediaFormat.java","lineNumber":98,"sourceCode":"\t\tMedia.Format.VIDEO_MP4, VideoFormat.MP4,\n\t\tMedia.Format.VIDEO_WEBM, VideoFormat.WEBM,\n\t\tMedia.Format.VIDEO_FLV, VideoFormat.FLV,\n\t\tMedia.Format.VIDEO_MPEG, VideoFormat.MPEG,\n\t\tMedia.Format.VIDEO_WMV, VideoFormat.WMV,\n\t\tMedia.Format.VIDEO_THREE_GP, VideoFormat.THREE_GP);\n\t// @formatter:on\n\n\tpublic static String getFormatAsString(MimeType mimeType) {\n\t\tif (isSupportedDocumentFormat(mimeType)) {\n\t\t\treturn getDocumentFormat(mimeType).toString();\n\t\t}\n\t\telse if (isSupportedImageFormat(mimeType)) {\n\t\t\treturn getImageFormat(mimeType).toString();\n\t\t}\n\t\telse if (isSupportedVideoFormat(mimeType)) {\n\t\t\treturn getVideoFormat(mimeType).toString();\n\t\t}\n\t\tthrow new IllegalArgumentException(\"Unsupported media format: \" + mimeType);\n\t}\n\n\tpublic static Boolean isSupportedDocumentFormat(MimeType mimeType) {\n\t\treturn DOCUMENT_MAP.containsKey(mimeType);\n\t}\n\n\tpublic static DocumentFormat getDocumentFormat(MimeType mimeType) {\n\t\tDocumentFormat format = DOCUMENT_MAP.get(mimeType);\n\t\tif (format == null) {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported document format: \" + mimeType);\n\t\t}\n\t\treturn format;\n\t}\n\n\tpublic static Boolean isSupportedImageFormat(MimeType mimeType) {\n\t\treturn IMAGE_MAP.containsKey(mimeType);\n\t}\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockMediaFormat.java#L80-L116","documentation":"BedrockMediaFormat.getFormatAsString maps a MimeType to its Bedrock string form. If the type is neither a supported document, image, nor video format, this IllegalArgumentException is thrown. Bedrock's Converse API accepts only a fixed set of media MIME types.","triggerScenarios":"Calling getFormatAsString with an unsupported MimeType, e.g. image/svg+xml, audio/mpeg, application/zip, or misspelled types like image/jpg.","commonSituations":"Rendering the media type name for prompts or config; passing audio to a chat model; using newer formats (webp/avif) not in the library's supported map; typos in MIME strings.","solutions":["Check BedrockMediaFormat.isSupportedDocumentFormat/isSupportedImageFormat/isSupportedVideoFormat first and handle unsupported types yourself.","Convert the media to a supported format before sending.","Fix MIME typos: use image/jpeg, not image/jpg.","Upgrade the Spring AI version if the format you need was added in a newer BedrockMediaFormat map."],"exampleFix":"// before\nString fmt = BedrockMediaFormat.getFormatAsString(media.getMimeType());\n// after\nif (!BedrockMediaFormat.isSupportedImageFormat(media.getMimeType())) {\n    throw new IllegalArgumentException(\"Convert media: \" + media.getMimeType());\n}\nString fmt = BedrockMediaFormat.getFormatAsString(media.getMimeType());","handlingStrategy":"validation","validationCode":"MimeType mt = media.getMimeType();\nif (!(Boolean.TRUE.equals(BedrockMediaFormat.isSupportedImageFormat(mt))\n   || Boolean.TRUE.equals(BedrockMediaFormat.isSupportedVideoFormat(mt))\n   || Boolean.TRUE.equals(BedrockMediaFormat.isSupportedDocumentFormat(mt)))) {\n    throw new IllegalArgumentException(\"MIME type not supported by Bedrock: \" + mt);\n}","typeGuard":"boolean hasStringFormat(MimeType mt) {\n    try { BedrockMediaFormat.getFormatAsString(mt); return true; }\n    catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":"try {\n    fmt = BedrockMediaFormat.getFormatAsString(mt);\n} catch (IllegalArgumentException e) {\n    fmt = null; // handle unsupported type upstream\n}","preventionTips":["Check the three isSupported*Format helpers before calling getFormatAsString","Use exact MIME constants (MimeTypeUtils) instead of hand-written strings","Convert exotic formats to supported ones at ingestion time","Pin library versions and re-check maps after upgrades"],"tags":["media","mime-type","unsupported-format","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"}