mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
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:
committed by
GitHub
parent
0a7a2f3e41
commit
528439cb4d
@@ -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),
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user