728x90
반응형
1. s3 nestjs와 연결하기
'nest g resource storages' 명령어를 통해 모듈 생성
2. ai.service에서 langchain 함수 사용시 이미지는 aws s3, 나머지는 db에 저장되게 만들기.
async bufferUploadToS3(fileName: string, buffer: Buffer, ext: string) {
try {
const command = new PutObjectCommand({
Bucket: this.configService.get('AWS_S3_BUCKET_NAME'),
Key: fileName,
Body: buffer,
ACL: 'public-read',
ContentType: `image/${ext}`,
});
await this.s3Client.send(command);
const region = this.configService.get('AWS_REGION');
const bucket = this.configService.get('AWS_S3_BUCKET_NAME');
return `https://s3.${region}.amazonaws.com/${bucket}/${fileName}`;
} catch (error) {
Logger.error(`bufferUploadToS3 실패: ${error.message}`);
throw new Error('Buffer 업로드 실패했습니다.');
}
}
728x90
반응형
'Storify' 카테고리의 다른 글
STORIFY (0123) - 단일 책임 원칙 (0) | 2024.01.24 |
---|---|
STORIFY (0122) - 종속성 순환 문제, 페이지네이션 (0) | 2024.01.23 |
STORIFY (0119) - API 구조 변경 (0) | 2024.01.19 |
STORIFY (0117) - 기술적 챌린지 (0) | 2024.01.17 |
STORIFY (0116) - DB Schema 설계 (0) | 2024.01.16 |