Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Allow customizing max file size in form-data payloads for webhooks #10857

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/@n8n/config/src/configs/endpoints.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions packages/@n8n/config/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ describe('GlobalConfig', () => {
formTest: 'form-test',
formWaiting: 'form-waiting',
payloadSizeMax: 16,
formDataFileSizeMax: 200,
rest: 'rest',
webhook: 'webhook',
webhookTest: 'webhook-test',
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/webhooks/webhook-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down
Loading