{"record":{"id":"beceefc5b4a2ffb2","repo":"n8n-io/n8n","slug":"binarydata-mimetype-is-not-a-supported-type-of","errorCode":null,"errorMessage":"${binaryData.mimeType} is not a supported type of binary data. Only images are supported.","messagePattern":"(.+?) is not a supported type of binary data\\. Only images are supported\\.","errorType":"exception","errorClass":"UnsupportedMimeTypeError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/methods/imageUtils.ts","lineNumber":17,"sourceCode":"import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { HumanMessage } from '@langchain/core/messages';\nimport { ChatGoogleGenerativeAI } from '@langchain/google-genai';\nimport { ChatOllama } from '@langchain/ollama';\nimport type { IExecuteFunctions, IBinaryData } from 'n8n-workflow';\nimport { NodeOperationError, NodeConnectionTypes, OperationalError } from 'n8n-workflow';\n\nimport type { MessageTemplate } from './types';\n\nexport class UnsupportedMimeTypeError extends OperationalError {}\n\n/**\n * Converts binary image data to a data URI\n */\nexport function dataUriFromImageData(binaryData: IBinaryData, bufferData: Buffer): string {\n\tif (!binaryData.mimeType?.startsWith('image/')) {\n\t\tthrow new UnsupportedMimeTypeError(\n\t\t\t`${binaryData.mimeType} is not a supported type of binary data. Only images are supported.`,\n\t\t);\n\t}\n\treturn `data:${binaryData.mimeType};base64,${bufferData.toString('base64')}`;\n}\n\n/**\n * Creates a human message with image content from either binary data or URL\n */\nexport async function createImageMessage({\n\tcontext,\n\titemIndex,\n\tmessage,\n}: {\n\tcontext: IExecuteFunctions;\n\titemIndex: number;\n\tmessage: MessageTemplate;\n}): Promise<HumanMessage> {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/nodes-langchain/nodes/chains/ChainLLM/methods/imageUtils.ts#L1-L35","documentation":"UnsupportedMimeTypeError (a subclass of OperationalError) is thrown by dataUriFromImageData when the supplied IBinaryData's mimeType does not begin with 'image/'. Vision-capable language models only accept image content, so the helper refuses to base64-encode a non-image file into a data URI.","triggerScenarios":"A binary property holding a PDF, video, audio file, or any non-image MIME type is passed as the binaryImageDataKey to createImageMessage / dataUriFromImageData. The check binaryData.mimeType?.startsWith('image/') returns false and the error is raised.","commonSituations":"User connected a 'Read Binary File' or HTTP file download to the image input of a ChainLLM Basic LLM Chain configured for vision, but the file is a PDF or document. The binary key on the item exists and is populated, but its content is not an image.","solutions":["Verify the binary file is actually an image (PNG, JPEG, GIF, WEBP) by checking $json.<key>.mimeType before the chain runs.","Point the node's binaryImageDataKey at the correct image property instead of a document/attachment property.","Pre-process non-image files: convert PDFs to images, or use a text-extraction node to get text instead of sending the binary as an image.","Filter items by mimeType upstream with an If node ({{ $binary.data.mimeType.startsWith('image/') }})."],"exampleFix":"// before — assumes any binary is an image\nconst dataURI = dataUriFromImageData(binaryData, bufferData);\n\n// after — guard before calling\nif (!binaryData.mimeType?.startsWith('image/')) {\n  throw new NodeOperationError(context.getNode(), {\n    message: `Expected an image, got ${binaryData.mimeType}. Convert the file to an image first.`,\n  });\n}\nconst dataURI = dataUriFromImageData(binaryData, bufferData);","handlingStrategy":"validation","validationCode":"// Validate mimeType before passing binary data to an image message\nfunction isImageBinary(b: { mimeType?: string } | undefined): b is { mimeType: string } {\n  return !!b?.mimeType?.startsWith('image/');\n}\n// usage\nif (!isImageBinary(item.binary?.[key])) {\n  // route to a non-image path or filter the item out\n}","typeGuard":"function isImageBinary(b: { mimeType?: string } | undefined): b is { mimeType: string } {\n  return typeof b?.mimeType === 'string' && b.mimeType.startsWith('image/');\n}","tryCatchPattern":"try {\n  const dataURI = dataUriFromImageData(binaryData, bufferData);\n} catch (e) {\n  if (e instanceof UnsupportedMimeTypeError) {\n    // handle: skip item, convert file, or notify user\n  } else throw e;\n}","preventionTips":["Filter items by $binary.<key>.mimeType.startsWith('image/') in an If node upstream.","Use a converter node for PDFs/documents before sending to a vision chain.","Confirm the upstream node is reading the file as an image format."],"tags":["binary-data","mime-type","vision-model","parameter-validation"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}