From 5be24af034d4d2fdb6ab63afb2bd5e2d711df6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 17 Sep 2024 14:58:43 +0200 Subject: [PATCH] feat(core): Allow customizing max file size in form-data payloads for webhooks --- packages/@n8n/config/src/configs/endpoints.config.ts | 4 ++++ packages/@n8n/config/test/config.test.ts | 1 + packages/cli/src/webhooks/webhook-helpers.ts | 3 +++ 3 files changed, 8 insertions(+) diff --git a/packages/@n8n/config/src/configs/endpoints.config.ts b/packages/@n8n/config/src/configs/endpoints.config.ts index 9905d9f48aaf0..4ec58ccf0d40d 100644 --- a/packages/@n8n/config/src/configs/endpoints.config.ts +++ b/packages/@n8n/config/src/configs/endpoints.config.ts @@ -65,6 +65,10 @@ export class EndpointsConfig { @Env('N8N_PAYLOAD_SIZE_MAX') payloadSizeMax: number = 16; + /** Max payload size for files in form-data webhook payloads in MiB */ + @Env('N8N_FORMDATA_FILE_SIZE_MAX') + formDataFileSizeMax: number = 200; + @Nested metrics: PrometheusMetricsConfig; diff --git a/packages/@n8n/config/test/config.test.ts b/packages/@n8n/config/test/config.test.ts index 118cf5a1bf757..f7c1d48e21c09 100644 --- a/packages/@n8n/config/test/config.test.ts +++ b/packages/@n8n/config/test/config.test.ts @@ -176,6 +176,7 @@ describe('GlobalConfig', () => { formTest: 'form-test', formWaiting: 'form-waiting', payloadSizeMax: 16, + formDataFileSizeMax: 200, rest: 'rest', webhook: 'webhook', webhookTest: 'webhook-test', diff --git a/packages/cli/src/webhooks/webhook-helpers.ts b/packages/cli/src/webhooks/webhook-helpers.ts index 3b5ffa3466df2..064ef95eb14a6 100644 --- a/packages/cli/src/webhooks/webhook-helpers.ts +++ b/packages/cli/src/webhooks/webhook-helpers.ts @@ -6,6 +6,7 @@ /* eslint-disable prefer-spread */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/restrict-template-expressions */ +import { GlobalConfig } from '@n8n/config'; import type express from 'express'; import formidable from 'formidable'; import get from 'lodash/get'; @@ -214,9 +215,11 @@ export async function executeWebhook( if (!binaryData) { const { contentType, encoding } = req; if (contentType === 'multipart/form-data') { + const { formDataFileSizeMax } = Container.get(GlobalConfig).endpoints; const form = formidable({ multiples: true, encoding: encoding as formidable.BufferEncoding, + maxFileSize: formDataFileSizeMax, // TODO: pass a custom `fileWriteStreamHandler` to create binary data files directly }); req.body = await new Promise((resolve) => {