From dd58f50387444b1ec5c6108fe91eb27db6d49883 Mon Sep 17 00:00:00 2001 From: Y8C68 Date: Fri, 3 Apr 2026 06:11:28 +0000 Subject: [PATCH] fix(server): handle missing ContentType in attachment download GET /api/attachments/:id crashes with "Cannot read properties of undefined (reading extension)" when the S3 object has no ContentType metadata. This happens when files are uploaded without explicit content type (e.g., via API integrations). mime.extension(undefined) returns undefined, which then causes the Content-Disposition header template to fail. Fix: fallback to "application/octet-stream" when ContentType is missing, and "bin" when mime.extension() returns undefined. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../server/src/modules/Attachments/Attachments.controller.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/server/src/modules/Attachments/Attachments.controller.ts b/packages/server/src/modules/Attachments/Attachments.controller.ts index f94f46715..cc431ed66 100644 --- a/packages/server/src/modules/Attachments/Attachments.controller.ts +++ b/packages/server/src/modules/Attachments/Attachments.controller.ts @@ -93,11 +93,12 @@ export class AttachmentsController { const data = await this.attachmentsApplication.get(documentId); const byte = await data.Body.transformToByteArray(); - const extension = mime.extension(data.ContentType); + const contentType = data.ContentType || 'application/octet-stream'; + const extension = mime.extension(contentType) || 'bin'; const buffer = Buffer.from(byte); res.set('Content-Disposition', `filename="${documentId}.${extension}"`); - res.set('Content-Type', data.ContentType); + res.set('Content-Type', contentType); res.send(buffer); }