表单多文件处理示例

中级

这是一个File Management领域的自动化工作流,包含 10 个节点。主要使用 SplitOut、FormTrigger、ReadWriteFile、SplitInBatches 等节点。 使用表单处理多个文件:二进制数据和循环的教程

前置要求
  • 无特殊前置要求,导入即可使用
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "A2JB4uRp5waIV6yk",
  "meta": {
    "instanceId": "7fa92e27b5251ec88f2defd7f57845c1dbcc7a04d820567eb23d60c71ce71d01",
    "templateCredsSetupCompleted": true
  },
  "name": "FormLoadFileExample",
  "tags": [],
  "nodes": [
    {
      "id": "be53d6d3-2416-482e-a714-4573fed4bfbb",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -440,
        -460
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "699f5089-7416-414a-8e95-3bdb8637a6d9",
      "name": "保存每个文件",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        -240,
        -400
      ],
      "parameters": {
        "options": {
          "append": false
        },
        "fileName": "=out_{{ $json.files.filename }}",
        "operation": "write",
        "dataPropertyName": "=files_{{$runIndex}}"
      },
      "typeVersion": 1
    },
    {
      "id": "c8c5f9e6-670b-405b-af1d-72eeb372303e",
      "name": "分离文件",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -780,
        -460
      ],
      "parameters": {
        "options": {
          "includeBinary": true,
          "destinationFieldName": "=files"
        },
        "fieldToSplitOut": "=files"
      },
      "executeOnce": false,
      "typeVersion": 1
    },
    {
      "id": "8f7252ac-4082-49b8-9e56-9d14689ee864",
      "name": "表单 - 加载多个文件",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -1220,
        -460
      ],
      "webhookId": "ff49b14a-c796-47ce-a629-8508182bfc4f",
      "parameters": {
        "options": {},
        "formTitle": "LOAD MULTIPLE FILES",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "files",
              "requiredField": true,
              "acceptFileTypes": "*.json"
            }
          ]
        },
        "formDescription": "Select multiple json files to run this example."
      },
      "typeVersion": 2.2
    },
    {
      "id": "72ee0e48-9a75-4c7d-af09-bcd5bbc5b2ba",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        -760
      ],
      "parameters": {
        "width": 1740,
        "height": 140,
        "content": "## 学习 n8n"
      },
      "typeVersion": 1
    },
    {
      "id": "962e91d5-eb75-4245-9dfb-4b13c15cdb0a",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1400,
        -600
      ],
      "parameters": {
        "color": 6,
        "width": 480,
        "height": 400,
        "content": "使用表单加载多个文件。"
      },
      "typeVersion": 1
    },
    {
      "id": "2aee5134-abc4-45f9-a2db-cf205f18cff7",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -900,
        -600
      ],
      "parameters": {
        "color": 6,
        "width": 360,
        "height": 400,
        "content": "拆分输出将解决此问题,为每个文件触发一个事件。"
      },
      "typeVersion": 1
    },
    {
      "id": "1ec83469-5dcd-4beb-9414-7f75a0727ed3",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -520,
        -600
      ],
      "parameters": {
        "color": 6,
        "width": 460,
        "height": 400,
        "content": "现在我们可以使用循环逐个处理每个文件。"
      },
      "typeVersion": 1
    },
    {
      "id": "2545fa3e-346b-4277-b494-f1c2d469dceb",
      "name": "继续一次",
      "type": "n8n-nodes-base.noOp",
      "position": [
        60,
        -480
      ],
      "parameters": {},
      "executeOnce": true,
      "typeVersion": 1
    },
    {
      "id": "d1646761-2962-4afb-9033-d13f7d853290",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -600
      ],
      "parameters": {
        "color": 6,
        "width": 380,
        "height": 400,
        "content": "我们通常只希望使用单个事件继续下游处理,因此这个设置为\"运行一次\"的 NOP 节点将让我们实现这一点,无论文件数量如何。"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "21acb21b-3bca-4279-9725-7d4fcd88b25f",
  "connections": {
    "Continue Once": {
      "main": [
        []
      ]
    },
    "Save Each File": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "Continue Once",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Save Each File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out Files": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Form - Load Multiple Files": {
      "main": [
        [
          {
            "node": "Split Out Files",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

这是一个中级难度的工作流,适用于File Management等场景。适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

需要付费吗?

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

工作流信息
难度等级
中级
节点数量10
分类1
节点类型6
难度说明

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

外部链接
在 n8n.io 上查看 →

分享此工作流