Loading...
Loading...
Compare original and translation side by side
$json$binaryn8n-data-tables$json$binaryn8n-data-tables$binary$json$jsonfromAi()passthroughBinaryImages: truereferences/AGENT_TOOL_BINARY.md$binary$json$jsonfromAi()passthroughBinaryImages: truereferences/AGENT_TOOL_BINARY.mdreferences/MERGE_FOR_CONTEXT.mdreferences/MERGE_FOR_CONTEXT.md{
json: { ... }, // your data
binary: { // your files
data: { // 'data' is the typical key; can be any name
data: '<base64>',
mimeType: 'application/pdf',
fileName: 'invoice.pdf',
fileExtension: 'pdf',
},
},
}$binary.<key>binaryPropertyName$binary{
json: { ... }, // 你的数据
binary: { // 你的文件
data: { // 'data'是常用键名;可自定义名称
data: '<base64>',
mimeType: 'application/pdf',
fileName: 'invoice.pdf',
fileExtension: 'pdf',
},
},
}$binary.<key>binaryPropertyName$binary$binaryreturn [{
json: { ... },
binary: {
data: {
data: Buffer.from(content).toString('base64'),
mimeType: 'text/plain',
fileName: 'output.txt',
},
},
}]$binaryreturn [{
json: { ... },
binary: {
data: {
data: Buffer.from(content).toString('base64'),
mimeType: 'text/plain',
fileName: 'output.txt',
},
},
}]// In a Code node
const buffer = await this.helpers.getBinaryDataBuffer(0, 'data')
const text = buffer.toString('utf-8')references/BINARY_BASICS.md// 在Code节点中
const buffer = await this.helpers.getBinaryDataBuffer(0, 'data')
const text = buffer.toString('utf-8')references/BINARY_BASICS.mdfiles[]passthroughBinaryImages: truefromAi()fileNamefromAi('imageName', '...', 'string'){ ok: true, file_id: '...', url: '...' }references/AGENT_TOOL_BINARY.mdfiles[]passthroughBinaryImages: truefromAi()fileNamefromAi('imageName', '...', 'string'){ ok: true, file_id: '...', url: '...' }references/AGENT_TOOL_BINARY.md[Source with binary] ─┬─→ [Edit Fields: transform JSON] ─┐
│ ├─→ [Merge: by position] ─→ [Email with attachment]
└─────────────────────────────────────┘references/MERGE_FOR_CONTEXT.md[包含二进制数据的源节点] ─┬─→ [Edit Fields:转换JSON] ─┐
│ ├─→ [Merge:按位置合并] ─→ [带附件的邮件节点]
└─────────────────────────────────────┘references/MERGE_FOR_CONTEXT.md$binaryreferences/CDN_REQUIREMENT.md$binaryreferences/CDN_REQUIREMENT.mdn8n-data-tablesn8n-data-tables| File | Read when |
|---|---|
| First time handling binary, or reading/writing the |
| Agent tool needs a user-uploaded file, or produces a file (the boundary in either direction) |
| Binary disappears after a JSON transform and needs to re-attach |
| Showing images in chat hub or other places that need URL-referenced images |
| 文件 | 阅读场景 |
|---|---|
| 首次处理二进制数据,或读写 |
| Agent工具需要处理用户上传的文件,或生成文件时(双向边界场景) |
| JSON转换后二进制数据丢失,需要重新附加时 |
| 在聊天中心或其他需要URL引用图片的场景中展示图片时 |
| Anti-pattern | What goes wrong | Fix |
|---|---|---|
Trying to read file content from | Binary isn't in | Use |
| Building an agent tool that returns binary directly | Tool output is JSON-only, so binary doesn't survive | Upload to storage, return key/URL in JSON (see |
Trying to pass uploaded chat files into a tool via | | Pre-stage uploads to storage, inject keys in the system prompt, and have the tool download by key |
Setting | The flag only affects what the LLM sees, not what tools receive | Still need the upload-and-pass-key pattern for tools |
| Losing binary after a JSON transform | The transform's output item doesn't have binary | Use Merge to combine the JSON output with the binary stream |
| Storing image in n8n binary and expecting chat hub to display | Chat hub needs URL-accessible images, not raw binary | Upload to CDN, embed URL in response |
| Hardcoding binary base64 in a Code node | Massive workflow JSON, slow, leaky | Reference binary via |
| 反模式 | 问题所在 | 修复方案 |
|---|---|---|
尝试从 | 二进制数据不在 | 使用 |
| 构建直接返回二进制数据的Agent工具 | 工具输出仅支持JSON格式,二进制数据无法保留 | 上传到存储服务,在JSON中返回密钥/URL(查看 |
尝试通过 | | 预先将上传文件存储到存储服务,在系统提示中注入密钥,让工具通过密钥下载 |
设置 | 该配置仅影响LLM能看到的内容,不影响工具接收的数据 | 仍需使用“上传并传递密钥”的模式来让工具处理文件 |
| JSON转换后丢失二进制数据 | 转换后的输出条目不包含二进制数据 | 使用Merge节点将JSON输出与二进制数据流合并 |
| 将图片存储在n8n的二进制数据中并期望聊天中心展示 | 聊天中心需要可通过URL访问的图片,而非原始二进制数据 | 上传到CDN,在响应中嵌入URL |
| 在Code节点中硬编码二进制数据的base64 | 工作流JSON体积过大、运行缓慢、易泄露 | 正确通过 |