pages
This commit is contained in:
parent
05d97e2c50
commit
bf78c9c20f
17
lib/s3.ts
17
lib/s3.ts
@ -23,20 +23,29 @@ export const s3Client = new S3Client({
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload a file to S3
|
* Upload a file to S3
|
||||||
|
* Similar implementation to mission-uploads.ts which works correctly with MinIO
|
||||||
*/
|
*/
|
||||||
export async function putObject(
|
export async function putObject(
|
||||||
key: string,
|
key: string,
|
||||||
content: string | Buffer,
|
content: string | Buffer,
|
||||||
contentType?: string
|
contentType?: string
|
||||||
): Promise<{ key: string; url?: 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,
|
Bucket: S3_CONFIG.bucket,
|
||||||
Key: key,
|
Key: key,
|
||||||
Body: typeof content === 'string' ? Buffer.from(content, 'utf-8') : content,
|
Body: buffer,
|
||||||
ContentType: contentType || 'text/plain',
|
ContentType: contentType || 'text/plain',
|
||||||
});
|
}));
|
||||||
|
|
||||||
await s3Client.send(command);
|
|
||||||
return { key };
|
return { key };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user