From 53e4fadb6bff3200c2ce02dac31af52b360c42e9 Mon Sep 17 00:00:00 2001 From: Taras Zakus Date: Thu, 15 May 2025 17:42:57 +0300 Subject: [PATCH] Fix inline file upload Current version of `bref/local-api-gateway` supports only 'Content-Type: multipart/form-data', whereas inline body (e.g. image/jpeg) is not encoded properly and the uploaded file is corrupted. This change resolves the issue. --- src/apiGateway.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/apiGateway.ts b/src/apiGateway.ts index 6c69703..fcc6937 100644 --- a/src/apiGateway.ts +++ b/src/apiGateway.ts @@ -35,7 +35,12 @@ export function httpRequestToEvent(request: Request): APIGatewayProxyEventV2 { ); const bodyString = Buffer.isBuffer(request.body) ? request.body.toString('utf8') : ''; - const shouldSendBase64 = request.method === 'GET' ? false : bodyString.includes('Content-Disposition: form-data'); + const shouldSendBase64 = request.method === 'GET' + ? false + : ( + bodyString.includes('Content-Disposition: form-data') || + (headers['content-disposition']?.startsWith('inline;') === true) + ); const cookies = request.headers.cookie ? request.headers.cookie.split('; ') : [];