import { s3 } from "@/lib/s3"; import { GetObjectCommand } from "@aws-sdk/client-s3"; import type { Readable } from "stream"; export async function getImageBufferFromS3Key(s3Key: string): Promise { const command = new GetObjectCommand({ Bucket: process.env.BUCKET_NAME, Key: s3Key, }); const response = await s3.send(command); const stream = response.Body as Readable; const chunks: Uint8Array[] = []; for await (const chunk of stream) chunks.push(chunk); return Buffer.concat(chunks); }