How to attach binary file to the ai agent in n8n, please explain
Here’s a general way to do it:
In n8n, AI nodes (such as OpenAI, Azure OpenAI, etc.) don’t directly accept binary files as input. Therefore, you must first transform the file into a format that the AI can process, such as plain text or Base64. Step-by-step instructions for attaching a binary file to the AI node (or any node that processes data):
File input node:
Use a node such as “Read Binary File,” “HTTP Request,” or “Webhook” to obtain the binary file. This will create a binary field in the data. This may need to be processed with a code node.
Verify the binary format:
In the node preview, make sure there is a field such as binary.data or binary.[file_name].
AI Agent / Custom Node:
In the AI Agent node (if you’re using one such as OpenAI, Azure OpenAI, etc.), check if it has a field where you can specify binary data. If the node doesn’t directly allow it, you may need to convert the binary to base64 using the “Move Binary Data” node and pass that text as input.
Extract From File
If the goal is to send base64-encoded files (e.g., an image or document) as part of the input:
- Binary File → base64: Move Binary Data node → operation: “Convert binary data to text”.
- base64 → JSON: The base64 must be passed as a field within a JSON object (if the AI agent expects it).