Skip to content

获取二进制数据缓冲区#

¥Get the binary data buffer

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

¥The binary data buffer contains all the binary file data processed by a workflow. You need to access it if you want to perform operations on the binary data, such as:

  • 数据操作:例如,向 CSV 文件添加列标题。

¥Manipulating the data: for example, adding column headers to a CSV file.

  • 在计算中使用数据:例如,基于此计算哈希值。

¥Using the data in calculations: for example, calculating a hash value based on it.

  • 复杂 HTTP 请求:例如,将文件上传与其他数据格式的发送结合起来。

¥Complex HTTP requests: for example, combining file upload with sending other data formats.

Not available in Python

使用 Python 时不支持 getBinaryDataBuffer()

¥getBinaryDataBuffer() isn't supported when using Python.

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

¥You can access the buffer using n8n's getBinaryDataBuffer() function:

1
2
3
4
5
6
7
8
9
/* 

* 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);

例如:

¥For example:

1
2
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 的表达式。

¥You should always use the getBinaryDataBuffer() function, and avoid using older methods of directly accessing the buffer, such as targeting it with expressions like items[0].binary.data.data.