跳到主要内容

获取二进制数据缓冲区#

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

  • 数据操作:例如为CSV文件添加列标题
  • 计算场景应用:例如基于数据计算哈希值
  • 复杂HTTP请求:例如将文件上传与其他数据格式发送相结合

Python环境不可用

使用Python时不支持getBinaryDataBuffer()函数。

可通过n8n的getBinaryDataBuffer()函数访问缓冲区:

/*  
* itemIndex: number. The index of the item in the input data.
* binaryPropertyName: string. The name of the binary property.
* The default in the Read/Write File From Disk node is 'data'.
*/
let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);

例如:

let binaryDataBufferItem = await this.helpers.getBinaryDataBuffer(0, 'data');
// Returns the data in the binary buffer for the first input item

请始终使用 getBinaryDataBuffer() 函数,避免直接访问缓冲区的旧方法,例如通过 items[0].binary.data.data 这类表达式来定位缓冲区。