mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Webhook Node): Binary data handling (#7804)
Github issue / Community forum post (link here to close automatically):
This commit is contained in:
@@ -38,7 +38,7 @@ export class Webhook extends Node {
|
||||
icon: 'file:webhook.svg',
|
||||
name: 'webhook',
|
||||
group: ['trigger'],
|
||||
version: 1,
|
||||
version: [1, 1.1],
|
||||
description: 'Starts the workflow when a webhook is called',
|
||||
eventTriggerDescription: 'Waiting for you to call the Test URL',
|
||||
activationMessage: 'You can now make calls to your production webhook URL.',
|
||||
@@ -125,6 +125,17 @@ export class Webhook extends Node {
|
||||
return this.handleFormData(context);
|
||||
}
|
||||
|
||||
const nodeVersion = context.getNode().typeVersion;
|
||||
if (nodeVersion > 1 && !req.body && !options.rawBody) {
|
||||
try {
|
||||
return await this.handleBinaryData(context);
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
if (options.rawBody && !req.rawBody) {
|
||||
await req.readRawBody();
|
||||
}
|
||||
|
||||
const response: INodeExecutionData = {
|
||||
json: {
|
||||
headers: req.headers,
|
||||
@@ -135,7 +146,7 @@ export class Webhook extends Node {
|
||||
binary: options.rawBody
|
||||
? {
|
||||
data: {
|
||||
data: req.rawBody.toString(BINARY_ENCODING),
|
||||
data: (req.rawBody ?? '').toString(BINARY_ENCODING),
|
||||
mimeType: req.contentType ?? 'application/json',
|
||||
},
|
||||
}
|
||||
@@ -215,6 +226,7 @@ export class Webhook extends Node {
|
||||
};
|
||||
|
||||
let count = 0;
|
||||
|
||||
for (const key of Object.keys(files)) {
|
||||
const processFiles: MultiPartFormData.File[] = [];
|
||||
let multiFile = false;
|
||||
@@ -247,6 +259,7 @@ export class Webhook extends Node {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return { workflowData: [[returnItem]] };
|
||||
}
|
||||
|
||||
@@ -272,12 +285,18 @@ export class Webhook extends Node {
|
||||
|
||||
const binaryPropertyName = (options.binaryPropertyName || 'data') as string;
|
||||
const fileName = req.contentDisposition?.filename ?? uuid();
|
||||
returnItem.binary![binaryPropertyName] = await context.nodeHelpers.copyBinaryFile(
|
||||
const binaryData = await context.nodeHelpers.copyBinaryFile(
|
||||
binaryFile.path,
|
||||
fileName,
|
||||
req.contentType ?? 'application/octet-stream',
|
||||
);
|
||||
|
||||
if (!binaryData.data) {
|
||||
return { workflowData: [[returnItem]] };
|
||||
}
|
||||
|
||||
returnItem.binary![binaryPropertyName] = binaryData;
|
||||
|
||||
return { workflowData: [[returnItem]] };
|
||||
} catch (error) {
|
||||
throw new NodeOperationError(context.getNode(), error as Error);
|
||||
|
||||
Reference in New Issue
Block a user