Skip to content

Commit

Permalink
Feat: Change aws endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ho-s committed Nov 21, 2024
1 parent 20f5b35 commit b82505d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/common/helper/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ export class EnvironmentVariables {
GPT_KEY: string;

@IsString()
NCP_ACCESS_KEY_ID: string;
AWS_S3_ACCESS_KEY: string;

@IsString()
NCP_SECRET_ACCESS_KEY: string;
AWS_S3_SECRET_KEY: string;

@IsString()
NCP_BUCKET_NAME: string;
AWS_S3_REGION: string;

@IsString()
NCP_ENDPOINT: string;
AWS_S3_BUCKET_NAME: string;
}

export function envValidation(config: Record<string, unknown>) {
Expand Down
13 changes: 7 additions & 6 deletions src/upload/upload.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

import AWS, { S3 } from 'aws-sdk';
import { S3 } from 'aws-sdk';

@Injectable()
export class UploadService {
private readonly awsS3: S3;

constructor(private readonly configService: ConfigService) {
this.awsS3 = new S3({
endpoint: new AWS.Endpoint(this.configService.get('NCP_ENDPOINT')),
accessKeyId: this.configService.get('NCP_ACCESS_KEY_ID'),
secretAccessKey: this.configService.get('NCP_SECRET_ACCESS_KEY'),
region: 'kr-standard',
region: this.configService.get('AWS_S3_REGION'),
credentials: {
accessKeyId: this.configService.get('AWS_S3_ACCESS_KEY'),
secretAccessKey: this.configService.get('AWS_S3_SECRET_KEY'),
},
});
}

async uploadFile(file: Express.Multer.File, folder: string = '') {
try {
const uploadResult = await this.awsS3
.upload({
Bucket: this.configService.get('NCP_BUCKET_NAME'),
Bucket: this.configService.get('AWS_S3_BUCKET_NAME'),
Key: folder + file.originalname,
Body: file.buffer,
ContentType: file.mimetype,
Expand Down

0 comments on commit b82505d

Please sign in to comment.