从文件提取(Extract From File)#
在 n8n 工作流中,一个常见的模式是接收文件,这些文件可能来自 HTTP 请求节点(用于从网站获取的文件)、Webhook 节点(用于从其他地方发送到你的工作流的文件),或者来自本地来源。以这种方式获取的数据通常是二进制格式,例如电子表格或 PDF。
🌐 A common pattern in n8n workflows is to receive a file, either from an HTTP Request node (for files you are fetching from a website), a Webhook Node (for files which are sent to your workflow from elsewhere), or from a local source. Data obtained in this way is often in a binary format, for example a spreadsheet or PDF.
“从文件提取”节点从二进制格式文件中提取数据并将其转换为 JSON,然后可以在工作流的其余部分中轻松操作。要将 JSON 转回二进制文件类型,请参阅 转换为文件 节点。
🌐 The Extract From File node extracts data from a binary format file and converts it to JSON, which can then be easily manipulated by the rest of your workflow. For converting JSON back into a binary file type, please see the Convert to File node.
操作(Operations)#
使用 操作 下拉菜单选择要从中提取数据的源文件格式。
🌐 Use the Operations drop-down to select the format of the source file to extract data from.
- 从 CSV 提取:"逗号分隔值" 文件类型通常用于表格数据。
- 从 HTML 中提取:从标准网页 HTML 格式文件中提取字段。
- 从 JSON 提取:从二进制文件中提取 JSON 数据。
- 从 ICS 提取:从 iCalendar 格式文件中提取字段。
- 从ODS提取:从ODS电子表格文件中提取字段。
- 从 PDF 提取:从可移植文档格式文件中提取字段。
- 从 RTF 中提取:从丰富文本格式文件中提取字段。
- 从文本文件提取:从标准文本文件格式中提取字段。
- 从 XLS 提取:从 Microsoft Excel 文件(旧格式)中提取字段。
- 从 XLSX 提取:从 Microsoft Excel 文件中提取字段。
- 将文件转换为Base64字符串:将二进制数据转换为适合文本的Base64格式。
示例工作流程(Example workflow)#
在此示例中,使用 Webhook 节点来触发工作流。当 CSV 文件发送到 webhook 地址时,文件数据将被输出并由“从文件提取”节点接收。
🌐 In this example, a Webhook node is used to trigger the workflow. When a CSV file is sent to the webhook address, the file data is output and received by the Extract From File node.
Workflow preview placeholder.
设置为“从 CSV 提取”操作后,该节点将把数据输出为一系列 JSON “行”对象:
🌐 Set to operate as 'Extract from CSV', the node then outputs the data as a series of JSON 'row' objects:
1 2 3 4 5 6 7 8 | |
通过 Webhook 接收文件
选择 Webhook 节点的 添加选项 按钮,然后选择 原始正文,启用该设置以使节点输出后续节点所期望的二进制文件。
节点参数(Node parameters)#
输入二进制字段(Input Binary Field)#
输入节点输入数据中包含二进制文件的字段名称。默认是“data”。
🌐 Enter the name of the field from the node input data that contains the binary file. The default is 'data'.
目标输出字段(Destination Output Field)#
输入节点输出中用于存储提取数据的字段名称。
🌐 Enter the name of the field in the node output that will contain the extracted data.
此参数仅适用于以下操作:
🌐 This parameter is only available for these operations:
- 从 JSON 文件提取:
- 从 ICS 文件提取:
- 从文本文件提取:
- 将文件转换为 Base64 字符串