From f61d779667f25a411b51ee61ddd3fe4698f05934 Mon Sep 17 00:00:00 2001 From: agobrech <45268029+agobrech@users.noreply.github.com> Date: Wed, 1 Mar 2023 18:14:07 +0100 Subject: [PATCH] feat(Jira Software Node): Support binary streaming for very large binary files (#5589) Move from buffer to binary streaming --- packages/nodes-base/nodes/Jira/Jira.node.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/nodes-base/nodes/Jira/Jira.node.ts b/packages/nodes-base/nodes/Jira/Jira.node.ts index 65393eeff5..884e2f7cbf 100644 --- a/packages/nodes-base/nodes/Jira/Jira.node.ts +++ b/packages/nodes-base/nodes/Jira/Jira.node.ts @@ -1,6 +1,8 @@ +import type { Readable } from 'stream'; import mergeWith from 'lodash.mergewith'; import type { IExecuteFunctions } from 'n8n-core'; +import { BINARY_ENCODING } from 'n8n-core'; import type { IBinaryKeyData, @@ -1061,12 +1063,9 @@ export class Jira implements INodeType { itemIndex: i, }); } - + let uploadData: Buffer | Readable; const item = items[i].binary as IBinaryKeyData; - const binaryData = item[binaryPropertyName]; - const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); - if (binaryData === undefined) { throw new NodeOperationError( this.getNode(), @@ -1075,6 +1074,12 @@ export class Jira implements INodeType { ); } + if (binaryData.id) { + uploadData = this.helpers.getBinaryStream(binaryData.id); + } else { + uploadData = Buffer.from(binaryData.data, BINARY_ENCODING); + } + responseData = await jiraSoftwareCloudApiRequest.call( this, `/api/${apiVersion}/issue/${issueKey}/attachments`, @@ -1085,7 +1090,7 @@ export class Jira implements INodeType { { formData: { file: { - value: binaryDataBuffer, + value: uploadData, options: { filename: binaryData.fileName, }, @@ -1154,7 +1159,7 @@ export class Jira implements INodeType { {}, {}, attachment?.json.content as string, - { json: false, encoding: null }, + { json: false, encoding: null, useStream: true }, ); (returnData[index].binary as IBinaryKeyData)[binaryPropertyName] = @@ -1205,7 +1210,7 @@ export class Jira implements INodeType { {}, {}, attachment.json.content as string, - { json: false, encoding: null }, + { json: false, encoding: null, useStream: true }, ); (returnData[index].binary as IBinaryKeyData)[binaryPropertyName] = await this.helpers.prepareBinaryData(