chore(s3): add console logs for upload/download operations (bucket, key, bytes, contentType)

This commit is contained in:
Ender 2025-10-24 02:57:36 +02:00
parent 1545310945
commit 18dfa5766c

View File

@ -25,6 +25,12 @@ export async function uploadBuffer(params: {
contentType?: string;
}) {
const s3 = getS3Client();
console.log('[S3] Upload start', {
bucket: params.bucket,
key: params.key,
bytes: params.body?.length ?? 0,
contentType: params.contentType || 'application/octet-stream',
});
const cmd = new PutObjectCommand({
Bucket: params.bucket,
Key: params.key,
@ -32,11 +38,13 @@ export async function uploadBuffer(params: {
ContentType: params.contentType || 'application/octet-stream',
});
await s3.send(cmd);
console.log('[S3] Upload done', { bucket: params.bucket, key: params.key });
return { bucket: params.bucket, key: params.key };
}
export async function downloadObject(params: { bucket: string; key: string }): Promise<{ buffer: Buffer; contentType: string }> {
const s3 = getS3Client();
console.log('[S3] Download start', { bucket: params.bucket, key: params.key });
const cmd = new GetObjectCommand({ Bucket: params.bucket, Key: params.key });
const res = await s3.send(cmd);
const contentType = res.ContentType || 'application/octet-stream';
@ -47,5 +55,7 @@ export async function downloadObject(params: { bucket: string; key: string }): P
body.on('end', resolve);
body.on('error', reject);
});
return { buffer: Buffer.concat(chunks), contentType };
const buffer = Buffer.concat(chunks);
console.log('[S3] Download done', { bucket: params.bucket, key: params.key, bytes: buffer.length, contentType });
return { buffer, contentType };
}