8
n8n 中文网amn8n.com

Google Drive文件加载器

中级

这是一个Building Blocks领域的自动化工作流,包含 8 个节点。主要使用 Set, Code, GoogleDocs, GoogleDrive, ExecuteWorkflowTrigger 等节点。 从Google Drive文件夹加载并聚合文件到键值字典

前置要求
  • Google Drive API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "Google Drive文件加载器",
  "nodes": [
    {
      "id": "3d066626-a87d-4e7b-bc16-9f47e1277dde",
      "name": "当由另一个工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "inputSource": "jsonExample",
        "jsonExample": "{\n}"
      },
      "typeVersion": 1.1
    },
    {
      "id": "cb0e5563-1550-4121-9fd5-b1cbd9810476",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        960,
        0
      ],
      "parameters": {
        "jsCode": "// n8n Code Node\n\n// Initialize an empty object to store the aggregated results\nconst aggregatedDict = {};\n\n// Get all input items passed to this node\nconst inputItems = $input.all();\n\n// Loop through each input item\nfor (const item of inputItems) {\n  // Get the JSON data from the current item\n  const itemJson = item.json;\n\n  // Check if item.json is actually an object and not null/undefined\n  // Also ensure it's not an array, as we expect key-value pairs\n  if (itemJson && typeof itemJson === 'object' && !Array.isArray(itemJson)) {\n\n    // Iterate over all the keys within the current item's JSON object\n    for (const key of Object.keys(itemJson)) {\n      // Add/overwrite the key-value pair to our aggregated dictionary\n      aggregatedDict[key] = itemJson[key].replaceAll(/\\n+/g, \"\\n\");\n      // console.log(`Adding/Updating key: ${key}`); // Optional: for debugging\n    }\n\n  } else {\n    // Optional: Log a warning if an item doesn't have the expected format\n    console.warn(`Skipping item - 'json' property is not a valid object:`, itemJson);\n  }\n}\n\n// n8n expects an array of items as output.\n// We return a single item containing the final aggregated dictionary in its 'json' property.\nreturn [{ json: aggregatedDict }];"
      },
      "typeVersion": 2
    },
    {
      "id": "1b90ca95-7251-4573-9b0b-4af3622721ba",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        140,
        -140
      ],
      "parameters": {
        "height": 300,
        "content": "## 步骤1"
      },
      "typeVersion": 1
    },
    {
      "id": "d26c2f27-0095-4dd6-9aa5-94c68f58bda3",
      "name": "从文件夹获取文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        220,
        0
      ],
      "parameters": {
        "filter": {
          "folderId": {
            "mode": "list",
            "value": "root",
            "cachedResultName": "/ (Root folder)"
          }
        },
        "options": {},
        "resource": "fileFolder"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "Ng83G9mU8KtY3wu6",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "938c8f7c-84b1-4eeb-a7c8-894ae5fbc275",
      "name": "下载Google文档",
      "type": "n8n-nodes-base.googleDocs",
      "position": [
        500,
        0
      ],
      "parameters": {
        "operation": "get",
        "documentURL": "={{ $json.id }}"
      },
      "credentials": {
        "googleDocsOAuth2Api": {
          "id": "bbAywBJpCuYeRX89",
          "name": "Google Docs account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "caa075a2-2e85-47e5-a829-425a1177e5be",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        -140
      ],
      "parameters": {
        "height": 300,
        "content": "## 步骤2"
      },
      "typeVersion": 1
    },
    {
      "id": "05db5439-584e-40aa-9c1d-101618f66fdc",
      "name": "映射",
      "type": "n8n-nodes-base.set",
      "position": [
        780,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b33e9355-659a-4b71-ba5c-00c90b7ed792",
              "name": "={{ $('Get files from folder').item.json.name }}",
              "type": "string",
              "value": "={{ $json.content }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "85dc7e65-7d50-4b13-b114-88b4020865e8",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        -140
      ],
      "parameters": {
        "color": 3,
        "width": 400,
        "height": 300,
        "content": "## 映射"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Mapping": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Google Docs": {
      "main": [
        [
          {
            "node": "Mapping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get files from folder": {
      "main": [
        [
          {
            "node": "Download Google Docs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Get files from folder",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 构建模块

需要付费吗?

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

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

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

作者
Hugues Stock

Hugues Stock

@hpstock

Hobbyist n8n automation maker, I build custom automations for people.

外部链接
在 n8n.io 查看

分享此工作流