8
n8n 中文网amn8n.com

使用代码节点模式恢复工作流节点间丢失的二进制数据

中级

这是一个Content Creation, Multimodal AI领域的自动化工作流,包含 8 个节点。主要使用 Set, Code, HttpRequest, ManualTrigger 等节点。 使用代码节点模式恢复工作流节点间丢失的二进制数据

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "creator": "Lucas Peyrin",
    "instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0",
    "fingerprint": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjcmVhdG9yIjoiIiwiaXNzIjoibjhuIiwiaWF0IjoxNzU4MzgyMTA3fQ.adMD662XvlKrH8GK9_H5LZlSpvrhUUTpD8AdPGY5Rok"
  },
  "nodes": [
    {
      "id": "acbfe599-0e66-43f8-acf8-92f3d863f963",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "重新访问前一节点的二进制数据",
      "type": "n8n-nodes-base.code",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        704,
        96
      ],
      "parameters": {
        "jsCode": "// IMPORTANT: Change this to the name of the node you want to get binary files from.\nconst previousNodeName = 'Get n8n Logo (Binary)';\n\n// This will hold all the items we process.\nconst allItems = [];\n\n// Loop over every item that is coming into this Code node.\nfor (const item of $input.all()) {\n\n  // For the current item in the loop, find its corresponding item from the previous node.\n  // The '.item' accessor automatically links the current item to its parent from the specified node.\n  const previousNodeItem = $(previousNodeName).item;\n\n  // Check if the corresponding item from the previous node actually has binary data.\n  if (previousNodeItem && previousNodeItem.binary) {\n\n    // Ensure the current item has a 'binary' object to add files to.\n    // This also prevents overwriting any binary data the current item might already have.\n    item.binary = item.binary || {};\n\n    // Now, loop over ALL keys (each key represents a file) in the binary object.\n    for (const inputPropertyName in previousNodeItem.binary) {\n      \n      // Get the specific binary file's data (which includes the base64 data and fileName).\n      const binary = previousNodeItem.binary[inputPropertyName];\n\n      // Decode the base64 data into a Buffer.\n      const myBuffer = Buffer.from(binary.data, 'base64');\n\n      // Use the n8n helper to prepare the binary data correctly for the next node\n      // and attach it to the current item's binary object using its original property name.\n      item.binary[inputPropertyName] = await this.helpers.prepareBinaryData(myBuffer, binary.fileName);\n    }\n  }\n\n  // Add the processed item (with its new binary data) to our results array.\n  allItems.push(item);\n}\n\n// Return all the processed items.\nreturn allItems;"
      },
      "typeVersion": 2
    },
    {
      "id": "8a68bb24-ee5a-44f6-bfc2-0beafe04e099",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "移除二进制数据",
      "type": "n8n-nodes-base.set",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        304,
        96
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "66ff2460-78b7-4231-b6ef-108acb51cd23",
              "name": "new_field",
              "type": "string",
              "value": "test value"
            }
          ]
        }
      },
      "typeVersion": 3.4,
      "alwaysOutputData": false
    },
    {
      "id": "17dc22f1-d81f-4511-a9b6-85f33d95ddbb",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "获取 n8n Logo(二进制)",
      "type": "n8n-nodes-base.httpRequest",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -32,
        96
      ],
      "parameters": {
        "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/53/N8n-logo-new.svg/2560px-N8n-logo-new.svg.png",
        "options": {}
      },
      "typeVersion": 4.2
    },
    {
      "id": "d1cd2a15-5ce1-4437-a123-d993550054c3",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "开始",
      "type": "n8n-nodes-base.manualTrigger",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -320,
        96
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "0df6b57c-c9e3-4bfc-a3a9-52403b6cd0d9",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "便签 (0)",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -592,
        -400
      ],
      "parameters": {
        "color": "0",
        "width": 448,
        "height": 544,
        "content": "## 重新访问二进制数据"
      },
      "typeVersion": 1
    },
    {
      "id": "e3e5944b-f2dd-4411-bd83-ab7755d95962",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "便签 (1)",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -112,
        -48
      ],
      "parameters": {
        "color": "7",
        "width": 256,
        "height": 192,
        "content": "此节点从 URL 获取二进制图像(n8n 徽标)。"
      },
      "typeVersion": 1
    },
    {
      "id": "ded5a9bd-a23e-4022-be31-905e30bef576",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "便签 (2)",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        176,
        -128
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 272,
        "content": "⚠️ **重要概念!**"
      },
      "typeVersion": 1
    },
    {
      "id": "da33a06c-e9a6-4945-bef7-4d0852ca78ef",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "便签 (3)",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "© 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        560,
        -320
      ],
      "parameters": {
        "color": "6",
        "width": 400,
        "height": 464,
        "content": "### 魔法在此发生!"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Get n8n Logo (Binary)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Remove Binary Data": {
      "main": [
        [
          {
            "node": "Re-Access Binary Data from Previous Node",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get n8n Logo (Binary)": {
      "main": [
        [
          {
            "node": "Remove Binary Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级 - 内容创作, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量8
分类2
节点类型5
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
Lucas Peyrin

Lucas Peyrin

@lucaspeyrin

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline. Get your Free n8n PDF Audit:

外部链接
在 n8n.io 查看

分享此工作流