Skip to content

获取二进制数据缓冲区#

二进制数据缓冲区包含工作流处理的所有二进制文件数据。如果您想对二进制数据执行操作,需要访问它,例如:

  • 操作数据:例如,向 CSV 文件添加列标题。
  • 在计算中使用数据:例如,基于它计算哈希值。
  • 复杂的 HTTP 请求:例如,将文件上传与发送其他数据格式结合。

Python 中不可用

使用 Python 时不支持 getBinaryDataBuffer()

您可以使用 n8n 的 getBinaryDataBuffer() 函数访问缓冲区:

1
2
3
4
5
6
/* 
* itemIndex: number. 输入数据中项目的索引。
* binaryPropertyName: string. 二进制属性的名称。
* 在从磁盘读取/写入文件节点中的默认值是 'data'。
*/
let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);

例如:

1
2
let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, 'data');
// 返回第一个输入项目的二进制缓冲区中的数据

您应该始终使用 getBinaryDataBuffer() 函数,并避免使用直接访问缓冲区的旧方法,例如使用表达式如 items[0].binary.data.data 来定位它。