{"record":{"id":"f01594d4802da112","repo":"spring-projects/spring-ai","slug":"unsupported-image-mime-type-mimetype","errorCode":null,"errorMessage":"Unsupported image mime type: ${mimeType}","messagePattern":"Unsupported image mime type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java","lineNumber":194,"sourceCode":"\t\tMedia media = document.getMedia();\n\t\tif (media != null) {\n\t\t\tif (media.getMimeType().isCompatibleWith(TEXT_MIME_TYPE)) {\n\t\t\t\tinstanceBuilder.text(media.getData().toString());\n\t\t\t\tdocumentMetadata.put(ModalityType.TEXT,\n\t\t\t\t\t\tnew DocumentMetadata(document.getId(), MimeTypeUtils.TEXT_PLAIN, media.getData()));\n\t\t\t\tif (logger.isWarnEnabled() && StringUtils.hasText(documentText)) {\n\t\t\t\t\tlogger.warn(\"Media type String overrides the Document text content!\");\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (media.getMimeType().isCompatibleWith(IMAGE_MIME_TYPE)) {\n\t\t\t\tif (SUPPORTED_IMAGE_MIME_SUB_TYPES.contains(media.getMimeType())) {\n\t\t\t\t\tinstanceBuilder.image(ImageBuilder.of(media.getMimeType()).imageData(media.getData()).build());\n\t\t\t\t\tdocumentMetadata.put(ModalityType.IMAGE,\n\t\t\t\t\t\t\tnew DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));\n\t\t\t\t}\n\t\t\t\telse if (logger.isWarnEnabled()) {\n\t\t\t\t\tlogger.warn(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t\tthrow new IllegalArgumentException(\"Unsupported image mime type: \" + media.getMimeType());\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if (media.getMimeType().isCompatibleWith(VIDEO_MIME_TYPE)) {\n\t\t\t\tinstanceBuilder.video(VideoBuilder.of(media.getMimeType())\n\t\t\t\t\t.videoData(media.getData())\n\t\t\t\t\t.startOffsetSec(mergedOptions.getVideoStartOffsetSec())\n\t\t\t\t\t.endOffsetSec(mergedOptions.getVideoEndOffsetSec())\n\t\t\t\t\t.intervalSec(mergedOptions.getVideoIntervalSec())\n\t\t\t\t\t.build());\n\t\t\t\tdocumentMetadata.put(ModalityType.VIDEO,\n\t\t\t\t\t\tnew DocumentMetadata(document.getId(), media.getMimeType(), media.getData()));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (logger.isWarnEnabled()) {\n\t\t\t\t\tlogger.warn(\"Unsupported media type: \" + media.getMimeType());\n\t\t\t\t}\n\t\t\t\tthrow new IllegalArgumentException(\"Unsupported media type: \" + media.getMimeType());\n\t\t\t}","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-vertex-ai-embedding/src/main/java/org/springframework/ai/vertexai/embedding/multimodal/VertexAiMultimodalEmbeddingModel.java#L176-L212","documentation":"VertexAiMultimodalEmbeddingModel.doSingleDocumentPrediction routes each media item in a document by MIME type. When a media item's type is image-like handling fails — specifically, an image with a MIME type not accepted by the Vertex multimodal embedding API is both logged as a warning and thrown as IllegalArgumentException. Only supported image MIME types (e.g. image/png, image/jpeg) can be embedded.","triggerScenarios":"Embedding a Document whose media list contains an image Media whose getMimeType() is not compatible with the image builder's accepted types — e.g. image/webp, image/tiff, or a malformed/missing MIME type.","commonSituations":"Uploading screenshots in unsupported formats (webp, bmp); files stored without correct MIME metadata; passing generic application/octet-stream typed images.","solutions":["Convert the image to a supported format (PNG or JPEG) before embedding","Fix the MIME type on the Media/Document if the file is actually PNG/JPEG but typed incorrectly","Pre-validate media MIME types in your pipeline and filter unsupported ones before calling the model"],"exampleFix":"// before\nMedia media = new Media(MimeTypeUtils.parseMimeType(\"image/webp\"), data);\n// after\nMedia media = new Media(new MimeType(\"image\", \"png\"), pngBytes); // converted beforehand","handlingStrategy":"validation","validationCode":"Set<MimeType> supported = Set.of(\n    new MimeType(\"image\",\"png\"), new MimeType(\"image\",\"jpeg\"));\nif (media.getMimeType() == null || !supported.contains(media.getMimeType())) {\n    throw new IllegalArgumentException(\"Unsupported image type: \" + media.getMimeType());\n}","typeGuard":null,"tryCatchPattern":"try {\n    embeddingModel.embed(document);\n} catch (IllegalArgumentException e) {\n    // convert or drop the offending media item\n}","preventionTips":["Normalize images to PNG/JPEG before embedding","Fix MIME metadata on stored files","Filter media by modality before building Documents"],"tags":["vertex-ai","mime-type","multimodal","embedding"],"backgroundTag":"unsupported-media-type","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}