From 224ef736de2831202319b0912cda142b9fb03cc5 Mon Sep 17 00:00:00 2001 From: Ahsan Virani Date: Mon, 3 Jan 2022 22:42:42 +0100 Subject: [PATCH] :bug: Binary data handling fixes (#2629) * Update node airtable * Update nodenextcloud * Update node spreadsheet * Update node cortex, dropbox, editImage nodes * Update node emailSend * Update node ftp * Update node googleDrive * Update node googleDrive fix * Update node youtube * Update node htmlExtract * Update node linkedIn * Update node mailgun * Update node matrix * Update node pipedrive * Update node readPdf * Update node facebookGraphApi * Update node httpRequest * Update node nocoDB * Update node httpRequest, respondToWebhook * Update node signi4 * Update node slack * Update node zulip * cleanup * fix generic funcs * :bug: Fix EditImage Node Co-authored-by: Jan Oberhauser --- .../nodes-base/nodes/Airtable/GenericFunctions.ts | 6 +----- packages/nodes-base/nodes/Cortex/Cortex.node.ts | 5 ++--- packages/nodes-base/nodes/Dropbox/Dropbox.node.ts | 7 ++----- .../nodes-base/nodes/EditImage/EditImage.node.ts | 10 ++++++---- .../nodes-base/nodes/EmailSend/EmailSend.node.ts | 7 ++----- .../nodes/Facebook/FacebookGraphApi.node.ts | 8 +++----- packages/nodes-base/nodes/Ftp/Ftp.node.ts | 9 +++------ .../nodes/Google/Drive/GoogleDrive.node.ts | 7 ++----- .../nodes-base/nodes/Google/YouTube/YouTube.node.ts | 9 +++------ .../nodes/HtmlExtract/HtmlExtract.node.ts | 4 +++- .../nodes/HttpRequest/HttpRequest.node.ts | 9 +++++---- packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts | 7 ++----- packages/nodes-base/nodes/Mailgun/Mailgun.node.ts | 8 +++----- .../nodes-base/nodes/Matrix/GenericFunctions.ts | 8 +++----- .../nodes-base/nodes/NextCloud/NextCloud.node.ts | 7 ++----- .../nodes-base/nodes/NocoDB/GenericFunctions.ts | 6 +----- .../nodes-base/nodes/Pipedrive/Pipedrive.node.ts | 3 +-- packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts | 7 ++----- .../nodes/RespondToWebhook/RespondToWebhook.node.ts | 8 ++++---- packages/nodes-base/nodes/S3/S3.node.ts | 13 +++---------- packages/nodes-base/nodes/SendGrid/SendGrid.node.ts | 5 +---- packages/nodes-base/nodes/Signl4/Signl4.node.ts | 8 +++----- packages/nodes-base/nodes/Slack/Slack.node.ts | 8 +++----- .../nodes/SpreadsheetFile/SpreadsheetFile.node.ts | 7 ++----- .../nodes-base/nodes/Telegram/GenericFunctions.ts | 1 - packages/nodes-base/nodes/Wait/Wait.node.ts | 1 + packages/nodes-base/nodes/Zulip/Zulip.node.ts | 5 +++-- 27 files changed, 66 insertions(+), 117 deletions(-) diff --git a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts index e85d1867f3..970e9323c7 100644 --- a/packages/nodes-base/nodes/Airtable/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Airtable/GenericFunctions.ts @@ -126,11 +126,7 @@ export async function downloadRecordAttachments(this: IExecuteFunctions | IPollF if (record.fields[fieldName] !== undefined) { for (const [index, attachment] of (record.fields[fieldName] as IAttachment[]).entries()) { const file = await apiRequest.call(this, 'GET', '', {}, {}, attachment.url, { json: false, encoding: null }); - element.binary![`${fieldName}_${index}`] = { - data: Buffer.from(file).toString('base64'), - fileName: attachment.filename, - mimeType: attachment.type, - }; + element.binary![`${fieldName}_${index}`] = await this.helpers.prepareBinaryData(Buffer.from(file), attachment.filename, attachment.type); } } } diff --git a/packages/nodes-base/nodes/Cortex/Cortex.node.ts b/packages/nodes-base/nodes/Cortex/Cortex.node.ts index 74d1d8c440..dfe25d1e00 100644 --- a/packages/nodes-base/nodes/Cortex/Cortex.node.ts +++ b/packages/nodes-base/nodes/Cortex/Cortex.node.ts @@ -1,5 +1,4 @@ import { - BINARY_ENCODING, IExecuteFunctions, } from 'n8n-core'; @@ -242,7 +241,7 @@ export class Cortex implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } - const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const options = { formData: { @@ -425,7 +424,7 @@ export class Cortex implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } - const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const sha256 = createHash('sha256').update(fileBufferData).digest('hex'); (body.data as IDataObject).attachment = { diff --git a/packages/nodes-base/nodes/Dropbox/Dropbox.node.ts b/packages/nodes-base/nodes/Dropbox/Dropbox.node.ts index 2fc0c5a264..41a6e54b11 100644 --- a/packages/nodes-base/nodes/Dropbox/Dropbox.node.ts +++ b/packages/nodes-base/nodes/Dropbox/Dropbox.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, @@ -859,7 +856,7 @@ export class Dropbox implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`); } - body = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING); + body = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); } else { // Is text file body = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8'); diff --git a/packages/nodes-base/nodes/EditImage/EditImage.node.ts b/packages/nodes-base/nodes/EditImage/EditImage.node.ts index 1326aa7ed3..136447f794 100644 --- a/packages/nodes-base/nodes/EditImage/EditImage.node.ts +++ b/packages/nodes-base/nodes/EditImage/EditImage.node.ts @@ -1179,7 +1179,8 @@ export class EditImage implements INodeType { throw new NodeOperationError(this.getNode(), `Item does not contain any binary data with the name "${dataPropertyName}".`); } - gmInstance = gm(Buffer.from(item.binary![dataPropertyName as string].data, BINARY_ENCODING)); + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, dataPropertyName); + gmInstance = gm(binaryDataBuffer); gmInstance = gmInstance.background('transparent'); } @@ -1218,7 +1219,8 @@ export class EditImage implements INodeType { const { fd, path, cleanup } = await file(); cleanupFunctions.push(cleanup); - await fsWriteFileAsync(fd, Buffer.from(item.binary![operationData.dataPropertyNameComposite as string].data, BINARY_ENCODING)); + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, operationData.dataPropertyNameComposite as string); + await fsWriteFileAsync(fd, binaryDataBuffer); if (operations[0].operation === 'create') { // It seems like if the image gets created newly we have to create a new gm instance @@ -1349,14 +1351,14 @@ export class EditImage implements INodeType { returnData.push(await (new Promise((resolve, reject) => { gmInstance - .toBuffer((error: Error | null, buffer: Buffer) => { + .toBuffer(async (error: Error | null, buffer: Buffer) => { cleanupFunctions.forEach(async cleanup => await cleanup()); if (error) { return reject(error); } - newItem.binary![dataPropertyName as string].data = buffer.toString(BINARY_ENCODING); + newItem.binary![dataPropertyName as string].data = (await this.helpers.prepareBinaryData(Buffer.from(buffer))).data; return resolve(newItem); }); diff --git a/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts b/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts index 999f63b7c3..a6abae2159 100644 --- a/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts +++ b/packages/nodes-base/nodes/EmailSend/EmailSend.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, INodeExecutionData, @@ -198,7 +195,7 @@ export class EmailSend implements INodeType { } attachments.push({ filename: item.binary[propertyName].fileName || 'unknown', - content: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING), + content: await this.helpers.getBinaryDataBuffer(itemIndex, propertyName), }); } diff --git a/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts b/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts index 9716003b48..21984cc352 100644 --- a/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts +++ b/packages/nodes-base/nodes/Facebook/FacebookGraphApi.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IBinaryData, IDataObject, @@ -391,9 +388,10 @@ export class FacebookGraphApi implements INodeType { const binaryProperty = item.binary[binaryPropertyName] as IBinaryData; + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName); requestOptions.formData = { [propertyName]: { - value: Buffer.from(binaryProperty.data, BINARY_ENCODING), + value: binaryDataBuffer, options: { filename: binaryProperty.fileName, contentType: binaryProperty.mimeType, diff --git a/packages/nodes-base/nodes/Ftp/Ftp.node.ts b/packages/nodes-base/nodes/Ftp/Ftp.node.ts index 78f34f3864..c373bb17bf 100644 --- a/packages/nodes-base/nodes/Ftp/Ftp.node.ts +++ b/packages/nodes-base/nodes/Ftp/Ftp.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { ICredentialDataDecryptedObject, IDataObject, @@ -503,7 +500,7 @@ export class Ftp implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`); } - const buffer = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING) as Buffer; + const buffer = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); await sftp!.put(buffer, remotePath); } else { // Is text file @@ -597,7 +594,7 @@ export class Ftp implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`); } - const buffer = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING) as Buffer; + const buffer = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); try { await ftp!.put(buffer, remotePath); diff --git a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts index 522c6a4462..45bf35f725 100644 --- a/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts +++ b/packages/nodes-base/nodes/Google/Drive/GoogleDrive.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, @@ -2423,7 +2420,7 @@ export class GoogleDrive implements INodeType { originalFilename = item.binary[propertyNameUpload].fileName; } - body = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING); + body = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); } else { // Is text file body = Buffer.from(this.getNodeParameter('fileContent', i) as string, 'utf8'); diff --git a/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts b/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts index c5c1a2a38a..29bcad1722 100644 --- a/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts +++ b/packages/nodes-base/nodes/Google/YouTube/YouTube.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, @@ -426,7 +423,7 @@ export class YouTube implements INodeType { mimeType = item.binary[binaryProperty].mimeType; } - const body = Buffer.from(item.binary[binaryProperty].data, BINARY_ENCODING); + const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const requestOptions = { headers: { @@ -913,7 +910,7 @@ export class YouTube implements INodeType { mimeType = item.binary[binaryProperty].mimeType; } - const body = Buffer.from(item.binary[binaryProperty].data, BINARY_ENCODING); + const body = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const requestOptions = { headers: { diff --git a/packages/nodes-base/nodes/HtmlExtract/HtmlExtract.node.ts b/packages/nodes-base/nodes/HtmlExtract/HtmlExtract.node.ts index 78cb0749b1..d3d2f1900c 100644 --- a/packages/nodes-base/nodes/HtmlExtract/HtmlExtract.node.ts +++ b/packages/nodes-base/nodes/HtmlExtract/HtmlExtract.node.ts @@ -240,7 +240,9 @@ export class HtmlExtract implements INodeType { if (item.binary[dataPropertyName] === undefined) { throw new NodeOperationError(this.getNode(), `No property named "${dataPropertyName}" exists!`); } - htmlArray = Buffer.from(item.binary[dataPropertyName].data, 'base64').toString('utf8'); + + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, dataPropertyName); + htmlArray = binaryDataBuffer.toString('utf-8'); } // Convert it always to array that it works with a string or an array of strings diff --git a/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts b/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts index b6826022cd..7ad64d59b7 100644 --- a/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts +++ b/packages/nodes-base/nodes/HttpRequest/HttpRequest.node.ts @@ -1,5 +1,4 @@ import { - BINARY_ENCODING, IExecuteFunctions, } from 'n8n-core'; import { @@ -771,8 +770,9 @@ export class HttpRequest implements INodeType { if (item.binary[binaryPropertyName] === undefined) { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } - const binaryProperty = item.binary[binaryPropertyName] as IBinaryData; - requestOptions.body = Buffer.from(binaryProperty.data, BINARY_ENCODING); + + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName); + requestOptions.body = binaryDataBuffer; } else if (options.bodyContentType === 'multipart-form-data') { requestOptions.body = {}; const binaryPropertyNameFull = this.getNodeParameter('binaryPropertyName', itemIndex) as string; @@ -794,9 +794,10 @@ export class HttpRequest implements INodeType { } const binaryProperty = item.binary[binaryPropertyName] as IBinaryData; + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName); requestOptions.body[propertyName] = { - value: Buffer.from(binaryProperty.data, BINARY_ENCODING), + value: binaryDataBuffer, options: { filename: binaryProperty.fileName, contentType: binaryProperty.mimeType, diff --git a/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts b/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts index 58a7e2a6ba..80cb1a875d 100644 --- a/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts +++ b/packages/nodes-base/nodes/LinkedIn/LinkedIn.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, ILoadOptionsFunctions, @@ -149,7 +146,7 @@ export class LinkedIn implements INodeType { } // Buffer binary data - const buffer = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING) as Buffer; + const buffer = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); // Upload image await linkedInApiRequest.call(this, 'POST', uploadUrl, buffer, true); diff --git a/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts b/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts index a2d35e9277..f2ce0d753d 100644 --- a/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts +++ b/packages/nodes-base/nodes/Mailgun/Mailgun.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, INodeExecutionData, @@ -158,8 +155,9 @@ export class Mailgun implements INodeType { if (!item.binary.hasOwnProperty(propertyName)) { continue; } + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(itemIndex, propertyName); attachments.push({ - value: Buffer.from(item.binary[propertyName].data, BINARY_ENCODING), + value: binaryDataBuffer, options: { filename: item.binary[propertyName].fileName || 'unknown', diff --git a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts index 1db691ab23..3293aff87d 100644 --- a/packages/nodes-base/nodes/Matrix/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Matrix/GenericFunctions.ts @@ -5,7 +5,6 @@ import { import { IDataObject, NodeApiError, NodeOperationError, } from 'n8n-workflow'; import { - BINARY_ENCODING, IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions, @@ -69,7 +68,7 @@ export async function matrixApiRequest(this: IExecuteFunctions | IExecuteSingleF } } -export async function handleMatrixCall(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, item: IDataObject, index: number, resource: string, operation: string): Promise { // tslint:disable-line:no-any +export async function handleMatrixCall(this: IExecuteFunctions, item: IDataObject, index: number, resource: string, operation: string): Promise { // tslint:disable-line:no-any if (resource === 'account') { if (operation === 'me') { @@ -193,13 +192,12 @@ export async function handleMatrixCall(this: IExecuteFunctions | IExecuteSingleF throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } - //@ts-ignore + // @ts-ignore qs.filename = item.binary[binaryPropertyName].fileName; //@ts-ignore filename = item.binary[binaryPropertyName].fileName; - //@ts-ignore - body = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + body = await this.helpers.getBinaryDataBuffer(index, binaryPropertyName); //@ts-ignore headers['Content-Type'] = item.binary[binaryPropertyName].mimeType; headers['accept'] = 'application/json,text/*;q=0.99'; diff --git a/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts b/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts index 538f14cebb..c916c99213 100644 --- a/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts +++ b/packages/nodes-base/nodes/NextCloud/NextCloud.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, @@ -1066,7 +1063,7 @@ export class NextCloud implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${propertyNameUpload}" does not exists on item!`); } - body = Buffer.from(item.binary[propertyNameUpload].data, BINARY_ENCODING); + body = await this.helpers.getBinaryDataBuffer(i, propertyNameUpload); } else { // Is text file body = this.getNodeParameter('fileContent', i) as string; diff --git a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts index b47ea6fb84..b4c6720640 100644 --- a/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts +++ b/packages/nodes-base/nodes/NocoDB/GenericFunctions.ts @@ -118,11 +118,7 @@ export async function downloadRecordAttachments(this: IExecuteFunctions | IPollF if (record[fieldName]) { for (const [index, attachment] of (JSON.parse(record[fieldName] as string) as IAttachment[]).entries()) { const file = await apiRequest.call(this, 'GET', '', {}, {}, attachment.url, { json: false, encoding: null }); - element.binary![`${fieldName}_${index}`] = { - data: Buffer.from(file).toString('base64'), - fileName: attachment.title, - mimeType: attachment.mimetype, - }; + element.binary![`${fieldName}_${index}`] = await this.helpers.prepareBinaryData(Buffer.from(file), attachment.title, attachment.mimetype); } } } diff --git a/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts b/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts index 8fc2154dfe..d565080aa4 100644 --- a/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts +++ b/packages/nodes-base/nodes/Pipedrive/Pipedrive.node.ts @@ -1,5 +1,4 @@ import { - BINARY_ENCODING, IExecuteFunctions, ILoadOptionsFunctions, } from 'n8n-core'; @@ -4500,7 +4499,7 @@ export class Pipedrive implements INodeType { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } - const fileBufferData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + const fileBufferData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); formData.file = { value: fileBufferData, diff --git a/packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts b/packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts index fbef80a90f..7ca735d547 100644 --- a/packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts +++ b/packages/nodes-base/nodes/ReadPdf/ReadPdf.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { INodeExecutionData, @@ -55,7 +52,7 @@ export class ReadPdf implements INodeType { item.binary = {}; } - const binaryData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + const binaryData = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName); returnData.push({ binary: item.binary, json: await pdf(binaryData), diff --git a/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts b/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts index 42467967cc..d73cddcd4c 100644 --- a/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts +++ b/packages/nodes-base/nodes/RespondToWebhook/RespondToWebhook.node.ts @@ -1,10 +1,9 @@ import { - BINARY_ENCODING, + IExecuteFunctions, } from 'n8n-core'; import { IDataObject, - IExecuteFunctions, IN8nHttpFullResponse, IN8nHttpResponse, INodeExecutionData, @@ -202,7 +201,7 @@ export class RespondToWebhook implements INodeType { ], }; - execute(this: IExecuteFunctions): Promise { + async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const respondWith = this.getNodeParameter('respondWith', 0) as string; @@ -250,6 +249,7 @@ export class RespondToWebhook implements INodeType { } const binaryData = item.binary[responseBinaryPropertyName]; + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(0, responseBinaryPropertyName); if (binaryData === undefined) { throw new NodeOperationError(this.getNode(), `No binary data property "${responseBinaryPropertyName}" does not exists on item!`); @@ -258,7 +258,7 @@ export class RespondToWebhook implements INodeType { if (headers['content-type']) { headers['content-type'] = binaryData.mimeType; } - responseBody = Buffer.from(binaryData.data, BINARY_ENCODING); + responseBody = binaryDataBuffer; } else if (respondWith !== 'noData') { throw new NodeOperationError(this.getNode(), `The Response Data option "${respondWith}" is not supported!`); } diff --git a/packages/nodes-base/nodes/S3/S3.node.ts b/packages/nodes-base/nodes/S3/S3.node.ts index 5f33fca1c8..72bfb8db0c 100644 --- a/packages/nodes-base/nodes/S3/S3.node.ts +++ b/packages/nodes-base/nodes/S3/S3.node.ts @@ -3,18 +3,11 @@ import { snakeCase, } from 'change-case'; -import { - createHash, -} from 'crypto'; +import { createHash } from 'crypto'; -import { - Builder, -} from 'xml2js'; +import { Builder } from 'xml2js'; -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IBinaryKeyData, diff --git a/packages/nodes-base/nodes/SendGrid/SendGrid.node.ts b/packages/nodes-base/nodes/SendGrid/SendGrid.node.ts index fc9f1f8ce2..1d843a5f15 100644 --- a/packages/nodes-base/nodes/SendGrid/SendGrid.node.ts +++ b/packages/nodes-base/nodes/SendGrid/SendGrid.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, diff --git a/packages/nodes-base/nodes/Signl4/Signl4.node.ts b/packages/nodes-base/nodes/Signl4/Signl4.node.ts index 5691763a88..d7a46663d3 100644 --- a/packages/nodes-base/nodes/Signl4/Signl4.node.ts +++ b/packages/nodes-base/nodes/Signl4/Signl4.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IBinaryKeyData, @@ -312,8 +309,9 @@ export class Signl4 implements INodeType { throw new NodeOperationError(this.getNode(), `Invalid extension, just ${supportedFileExtension.join(',')} are supported}`); } + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, propertyName); data.attachment = { - value: Buffer.from(binaryProperty.data, BINARY_ENCODING), + value: binaryDataBuffer, options: { filename: binaryProperty.fileName, contentType: binaryProperty.mimeType, diff --git a/packages/nodes-base/nodes/Slack/Slack.node.ts b/packages/nodes-base/nodes/Slack/Slack.node.ts index 14256178a4..c36ff8908f 100644 --- a/packages/nodes-base/nodes/Slack/Slack.node.ts +++ b/packages/nodes-base/nodes/Slack/Slack.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { ICredentialsDecrypted, @@ -977,9 +974,10 @@ export class Slack implements INodeType { || items[i].binary[binaryPropertyName] === undefined) { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryPropertyName}" does not exists on item!`); } + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); body.file = { //@ts-ignore - value: Buffer.from(items[i].binary[binaryPropertyName].data, BINARY_ENCODING), + value: binaryDataBuffer, options: { //@ts-ignore filename: items[i].binary[binaryPropertyName].fileName, diff --git a/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts b/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts index 5b70b3e39b..9b6ea32dfb 100644 --- a/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts +++ b/packages/nodes-base/nodes/SpreadsheetFile/SpreadsheetFile.node.ts @@ -1,7 +1,4 @@ -import { - BINARY_ENCODING, - IExecuteFunctions, -} from 'n8n-core'; +import { IExecuteFunctions } from 'n8n-core'; import { IDataObject, @@ -346,7 +343,7 @@ export class SpreadsheetFile implements INodeType { } // Read the binary spreadsheet data - const binaryData = Buffer.from(item.binary[binaryPropertyName].data, BINARY_ENCODING); + const binaryData = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); let workbook; if (options.readAsString === true) { workbook = xlsxRead(binaryData.toString(), { type: 'string', raw: options.rawData as boolean }); diff --git a/packages/nodes-base/nodes/Telegram/GenericFunctions.ts b/packages/nodes-base/nodes/Telegram/GenericFunctions.ts index 4ed4eec279..e1bce013e5 100644 --- a/packages/nodes-base/nodes/Telegram/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Telegram/GenericFunctions.ts @@ -1,5 +1,4 @@ import { - BINARY_ENCODING, IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions, diff --git a/packages/nodes-base/nodes/Wait/Wait.node.ts b/packages/nodes-base/nodes/Wait/Wait.node.ts index accc79f94d..20280377bd 100644 --- a/packages/nodes-base/nodes/Wait/Wait.node.ts +++ b/packages/nodes-base/nodes/Wait/Wait.node.ts @@ -1,4 +1,5 @@ import { + BINARY_ENCODING, IExecuteFunctions, WAIT_TIME_UNLIMITED, } from 'n8n-core'; diff --git a/packages/nodes-base/nodes/Zulip/Zulip.node.ts b/packages/nodes-base/nodes/Zulip/Zulip.node.ts index 67489c82ec..6f5d945c94 100644 --- a/packages/nodes-base/nodes/Zulip/Zulip.node.ts +++ b/packages/nodes-base/nodes/Zulip/Zulip.node.ts @@ -1,5 +1,4 @@ import { - BINARY_ENCODING, IExecuteFunctions, } from 'n8n-core'; import { @@ -217,10 +216,12 @@ export class Zulip implements INodeType { if (items[i].binary[binaryProperty] === undefined) { throw new NodeOperationError(this.getNode(), `No binary data property "${binaryProperty}" does not exists on item!`); } + + const binaryDataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryProperty); const formData = { file: { //@ts-ignore - value: Buffer.from(items[i].binary[binaryProperty].data, BINARY_ENCODING), + value: binaryDataBuffer, options: { //@ts-ignore filename: items[i].binary[binaryProperty].fileName,