From bf78c9c20f2b8359e30de2b6b2f4a259cef1f174 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 11 Jan 2026 23:20:04 +0100 Subject: [PATCH] pages --- lib/s3.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/s3.ts b/lib/s3.ts index 24941ef..cd50132 100644 --- a/lib/s3.ts +++ b/lib/s3.ts @@ -23,20 +23,29 @@ export const s3Client = new S3Client({ /** * Upload a file to S3 + * Similar implementation to mission-uploads.ts which works correctly with MinIO */ export async function putObject( key: string, content: string | Buffer, contentType?: string ): Promise<{ key: string; url?: string }> { - const command = new PutObjectCommand({ + // Convert string to Buffer consistently, exactly like mission-uploads.ts + // This ensures the same encoding and buffer handling that works for mission attachments + const buffer = typeof content === 'string' + ? Buffer.from(content, 'utf-8') + : Buffer.isBuffer(content) + ? content + : Buffer.from(content); + + // Use the same pattern as mission-uploads.ts: direct s3Client.send with PutObjectCommand + await s3Client.send(new PutObjectCommand({ Bucket: S3_CONFIG.bucket, Key: key, - Body: typeof content === 'string' ? Buffer.from(content, 'utf-8') : content, + Body: buffer, ContentType: contentType || 'text/plain', - }); + })); - await s3Client.send(command); return { key }; }