Files
MinglarBackendNestJS/src/common/middlewares/aws/getPreSignedUrl.ts

19 lines
521 B
TypeScript

// common/utils/awsPresign.ts
import config from "@/config/config";
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const s3 = new S3Client({
region: config.aws.region, // e.g. ap-south-1
});
export const getPresignedUrl = async (bucket: string, key: string) => {
const command = new GetObjectCommand({
Bucket: bucket,
Key: key,
});
// URL valid for 1 hour
return await getSignedUrl(s3, command, { expiresIn: 3600 });
};