vision-agent / lib /aws.ts
wuyiqunLu
feat: support png and mp4 rendering (#73)
1a37272 unverified
raw
history blame
1.05 kB
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
import { S3Client } from '@aws-sdk/client-s3';
import { fromEnv } from '@aws-sdk/credential-providers';
const FILE_SIZE_LIMIT = 104857600; // 100MB
const s3Client = new S3Client({
region: process.env.AWS_REGION,
credentials: fromEnv(),
});
export const getPresignedUrl = async (
fileName: string,
fileType: string,
id: string,
user: string,
) => {
const signedFileName = `${user}/${id}/${fileName}`;
const res = await createPresignedPost(s3Client, {
Bucket: process.env.AWS_BUCKET_NAME ?? 'vision-agent-dev',
Key: signedFileName,
Conditions: [
['content-length-range', 0, FILE_SIZE_LIMIT],
['starts-with', '$Content-Type', fileType],
],
Fields: {
acl: 'public-read',
'Content-Type': fileType,
},
Expires: 600,
});
return {
id,
signedUrl: res.url,
publicUrl: `https://${process.env.AWS_BUCKET_NAME}.s3.${process.env.AWS_REGION}.amazonaws.com/${signedFileName}`,
fields: res.fields,
};
};