This commit is contained in:
alma 2026-01-11 23:20:04 +01:00
parent 05d97e2c50
commit bf78c9c20f

View File

@ -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 };
}