From 9420b0fdf8ccccb95780c8c97e2b5d14cc4d513e Mon Sep 17 00:00:00 2001 From: agobrech <45268029+agobrech@users.noreply.github.com> Date: Fri, 3 Mar 2023 18:11:27 +0100 Subject: [PATCH] feat(Slack Node): Move from Binary Buffer to Binary streaming (#5612) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✨ Add Binary streaming instead of binary buffering --- .../nodes-base/nodes/Slack/V2/SlackV2.node.ts | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/nodes-base/nodes/Slack/V2/SlackV2.node.ts b/packages/nodes-base/nodes/Slack/V2/SlackV2.node.ts index da2dedff5f..5bed04d053 100644 --- a/packages/nodes-base/nodes/Slack/V2/SlackV2.node.ts +++ b/packages/nodes-base/nodes/Slack/V2/SlackV2.node.ts @@ -1,5 +1,6 @@ -/* eslint-disable n8n-nodes-base/node-filename-against-convention */ import type { IExecuteFunctions } from 'n8n-core'; +import { BINARY_ENCODING } from 'n8n-core'; +import type { Readable } from 'stream'; import type { IDataObject, @@ -1072,18 +1073,21 @@ export class SlackV2 implements INodeType { { itemIndex: i }, ); } - const binaryDataBuffer = await this.helpers.getBinaryDataBuffer( - i, - binaryPropertyName, - ); + let uploadData: Buffer | Readable; + const itemBinaryData = items[i].binary![binaryPropertyName]; + if (itemBinaryData.id) { + uploadData = this.helpers.getBinaryStream(itemBinaryData.id); + } else { + uploadData = Buffer.from(itemBinaryData.data, BINARY_ENCODING); + } body.file = { //@ts-ignore - value: binaryDataBuffer, + value: uploadData, options: { //@ts-ignore - filename: items[i].binary[binaryPropertyName].fileName, + filename: itemBinaryData.fileName, //@ts-ignore - contentType: items[i].binary[binaryPropertyName].mimeType, + contentType: itemBinaryData.mimeType, }, }; responseData = await slackApiRequest.call(