Skip to content

Commit 4f854eb

Browse files
committed
refactor image upload to use a buffer variable and add logging for buffer length
1 parent 622e15c commit 4f854eb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/app/api/uploadImage/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ export async function POST(req: NextRequest) {
4141
});
4242
const bucket = process.env.AWS_BUCKET_NAME || "";
4343
const key = `uploads/${randomUUID()}`; // Define your folder structure as desired
44+
const buffer = Buffer.from(await file.arrayBuffer());
4445

46+
console.log("Buffer Created", buffer.length);
4547
try {
4648
// Upload to S3
4749
const uploadParams = {
4850
Bucket: bucket,
4951
Key: key,
50-
Body: Buffer.from(await file.arrayBuffer()), // Convert file to buffer
52+
Body: buffer,
5153
ContentType: file.type,
5254
};
5355
const upload = await awsClient.send(new PutObjectCommand(uploadParams), {

0 commit comments

Comments
 (0)