Skip to content

Commit

Permalink
πŸ’š Refactored Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush-Vish committed Oct 29, 2024
1 parent 4ff588e commit 900b977
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions utils/src/lib/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,24 @@ export const uploadFileToS3 = async (
if (!file || !file.buffer) {
throw new Error('Invalid file data');
}
console.time();
console.time("upload" );
const buffer = await sharp(file.buffer)
.resize({})
.toBuffer();
console.timeEnd();
console.timeEnd("upload");

const params = {
Bucket: bucketName,
Key: crypto.randomBytes(32).toString('hex') + file.originalname,
Key: Date.now() + file.originalname,
Body: buffer,
ContentType: file.mimetype,
};

try {
console.time("S3")
const command = new PutObjectCommand(params);
await s3.send(command);
console.timeEnd("S3")
return {
url: `https://${bucketName}.s3.${process.env.AWS_REGION}.amazonaws.com/${params.Key}`,
};
Expand Down

0 comments on commit 900b977

Please sign in to comment.