Skip to content

Commit

Permalink
feat : sharp 모듈을 이용해 이미지 리사이징 #35
Browse files Browse the repository at this point in the history
Co-authored-by: LeeTH916 <[email protected]>
  • Loading branch information
GeunH and LeeTH916 committed Dec 9, 2023
1 parent 902eddd commit ef613cf
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions be/src/aws/aws.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from "@nestjs/common";
import * as AWS from "aws-sdk";
import { awsConfig } from "objectStorage.config";
import { v4 } from "uuid";
import * as sharp from "sharp";

@Injectable()
export class AwsService {
Expand All @@ -18,12 +18,21 @@ export class AwsService {
});
}

async uploadToS3(path: string, data: Buffer){
await this.s3.putObject({
Bucket: awsConfig.bucket,
Key: path,
Body: data,
}).promise();
async uploadToS3(path: string, data: Buffer) {

try {
const resizedBuffer = await sharp(data)
.resize(256, 256)
.toBuffer();

await this.s3.putObject({
Bucket: awsConfig.bucket,
Key: path,
Body: resizedBuffer,
}).promise();
} catch (error) {
throw error;
}
}

getImageURL(path: string) {
Expand Down

0 comments on commit ef613cf

Please sign in to comment.