fix(Microsoft Outlook Node): Fix binary attachment upload (#4766)

fix(Microsoft Outlook Node): fix binary attachment upload in file-system mode
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2022-11-30 10:57:13 +01:00
committed by GitHub
parent 0a7a2f3e41
commit 528439cb4d
2 changed files with 57 additions and 78 deletions

View File

@@ -1,8 +1,19 @@
import { OptionsWithUri } from 'request';
import { IExecuteFunctions, IExecuteSingleFunctions, ILoadOptionsFunctions } from 'n8n-core';
import {
BINARY_ENCODING,
IExecuteFunctions,
IExecuteSingleFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject, INodeExecutionData, NodeApiError } from 'n8n-workflow';
import {
IBinaryKeyData,
IDataObject,
INodeExecutionData,
NodeApiError,
NodeOperationError,
} from 'n8n-workflow';
export async function microsoftApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
@@ -221,3 +232,39 @@ export async function downloadAttachments(
}
return elements;
}
export async function binaryToAttachments(
this: IExecuteFunctions,
attachments: IDataObject[],
items: INodeExecutionData[],
i: number,
) {
return Promise.all(
attachments.map(async (attachment) => {
const { binary } = items[i];
if (binary === undefined) {
throw new NodeOperationError(this.getNode(), 'No binary data exists on item!', {
itemIndex: i,
});
}
const binaryPropertyName = attachment.binaryPropertyName as string;
if (binary[binaryPropertyName] === undefined) {
throw new NodeOperationError(
this.getNode(),
`No binary data property "${binaryPropertyName}" does not exists on item!`,
{ itemIndex: i },
);
}
const binaryData = (binary as IBinaryKeyData)[binaryPropertyName];
const dataBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
return {
'@odata.type': '#microsoft.graph.fileAttachment',
name: binaryData.fileName,
contentBytes: dataBuffer.toString(BINARY_ENCODING),
};
}),
);
}