Files
jaejadle/nextjs/lib/s3.ts
Mayne0213 f78454c2a1
Some checks failed
Build Docker Image / build-and-push (push) Has been cancelled
CI / lint-and-build (push) Has been cancelled
CHORE(merge): merge from develop
- Initial setup and all features from develop branch
- Includes: auth, deploy, docker, style fixes
- K3S deployment configuration
2026-01-06 17:29:16 +09:00

45 lines
1.0 KiB
TypeScript

import { GetObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { S3_CONFIG, s3Client } from '@/const';
/**
* S3 파일의 signed URL 생성 (1시간 유효)
*/
export async function generateSignedUrl(
fileKey: string,
options?: {
fileName?: string;
expiresIn?: number;
}
): Promise<string> {
const command = new GetObjectCommand({
Bucket: S3_CONFIG.BUCKET_NAME,
Key: fileKey,
...(options?.fileName && {
ResponseContentDisposition: `attachment; filename="${encodeURIComponent(options.fileName)}"`,
}),
});
return getSignedUrl(s3Client, command, {
expiresIn: options?.expiresIn || 3600
});
}
/**
* 여러 파일의 signed URL 일괄 생성
*/
export async function generateSignedUrls(
fileKeys: string[]
): Promise<Map<string, string>> {
const urlMap = new Map<string, string>();
await Promise.all(
fileKeys.map(async (fileKey) => {
const url = await generateSignedUrl(fileKey);
urlMap.set(fileKey, url);
})
);
return urlMap;
}