8
n8n 中文网amn8n.com

模板_Base64编码

中级

这是一个File Management领域的自动化工作流,包含 9 个节点。主要使用 Set, ConvertToFile, ManualTrigger, ExtractFromFile 等节点。 通过文件处理将JSON对象转换为Base64字符串

前置要求
  • 无特殊前置要求,导入即可使用
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "Templates_Base64_Encode",
  "nodes": [
    {
      "id": "923f05ea-cd34-4116-8c1d-83a51fe0080c",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 480,
        "height": 320,
        "content": "## 创建示例 JSON 数据"
      },
      "typeVersion": 1
    },
    {
      "id": "d1a367bc-f372-40ef-ac8a-abc6326a6b8c",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 440,
        "height": 320,
        "content": "## 将 JSON 字符串化并保存为二进制"
      },
      "typeVersion": 1
    },
    {
      "id": "960842f1-5017-415f-80b6-4e21d2c0c51d",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        -140
      ],
      "parameters": {
        "color": 4,
        "width": 360,
        "height": 320,
        "content": "## 将二进制数据转换为 Base64 编码字符串"
      },
      "typeVersion": 1
    },
    {
      "id": "f0b298ab-18f7-414a-ae27-76266830029c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -580,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 1320,
        "content": "## 将 JSON 编码为 Base64 字符串"
      },
      "typeVersion": 1
    },
    {
      "id": "dd1d4e6b-40ee-4d37-97c0-6bc4d1c9d560",
      "name": "创建 JSON 数据",
      "type": "n8n-nodes-base.set",
      "position": [
        -300,
        -20
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"string\": \"Hello, world!\",\n  \"number\": 42,\n  \"float\": 3.14,\n  \"booleanTrue\": true,\n  \"booleanFalse\": false,\n  \"nullValue\": null,\n  \"array\": [1, \"two\", false, null],\n  \"nestedObject\": {\n    \"id\": 1,\n    \"name\": \"Nested\",\n    \"attributes\": {\n      \"active\": true,\n      \"tags\": [\"test\", \"sample\"]\n    }\n  },\n  \"arrayOfObjects\": [\n    { \"type\": \"A\", \"value\": 10 },\n    { \"type\": \"B\", \"value\": 20 }\n  ],\n  \"emptyArray\": [],\n  \"emptyObject\": {}\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "c25f38bf-72a1-4fe3-89b9-dcf0d1d34e30",
      "name": "手动执行",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -520,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "dcf01114-59d8-4c25-8ee3-5405bed263f2",
      "name": "将 JSON 转换为字符串",
      "type": "n8n-nodes-base.set",
      "position": [
        -20,
        -20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "75e77a08-177d-46dc-bf82-69348bae9e76",
              "name": "json_text",
              "type": "string",
              "value": "={{ JSON.stringify($json) }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "17547a53-ec81-4050-96fe-f1f73542ce85",
      "name": "从二进制中提取 Base64",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        460,
        -20
      ],
      "parameters": {
        "options": {},
        "operation": "binaryToPropery",
        "destinationKey": "base64_text",
        "binaryPropertyName": "encoded_text"
      },
      "typeVersion": 1
    },
    {
      "id": "dd01f82c-2abb-48ff-acbe-0584721225b0",
      "name": "将字符串转换为二进制",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        180,
        -20
      ],
      "parameters": {
        "options": {
          "encoding": "utf8"
        },
        "operation": "toText",
        "sourceProperty": "json_text",
        "binaryPropertyName": "encoded_text"
      },
      "typeVersion": 1.1
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "Create Json Data": {
      "main": [
        [
          {
            "node": "Convert JSON to String",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Manual Execution": {
      "main": [
        [
          {
            "node": "Create Json Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert JSON to String": {
      "main": [
        [
          {
            "node": "Convert String to Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert String to Binary": {
      "main": [
        [
          {
            "node": "Extract Base64 from Binary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Base64 from Binary": {
      "main": [
        []
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 文件管理

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流