feature/aws-s3-upload #36

Merged
qcast3 merged 15 commits from feature/aws-s3-upload into dev 2025-05-13 16:21:10 +09:00
2 changed files with 16 additions and 4 deletions
Showing only changes of commit 8d645d08dc - Show all commits

View File

@ -36,7 +36,6 @@ export async function POST(req) {
const file = formData.get('file')
const result = await uploadImage(file)
result.message = '이미지 업로드 성공'
return NextResponse.json(result)
} catch (error) {

View File

@ -75,7 +75,10 @@ export async function POST(req) {
const OriginalKey = `Drawing/${uuidv4()}`
// Upload original image
/**
* 원본 이미지를 우선 저장한다.
* 이미지 이름이 겹지는 현상을 방지하기 위해 uuid 사용한다.
*/
await s3.send(
new PutObjectCommand({
Bucket,
@ -85,12 +88,19 @@ export async function POST(req) {
}),
)
// Process the image
/**
* 저장된 원본 이미지를 기준으로 크롭여부를 결정하여 크롭 이미지를 저장한다.
*/
const bufferImage = await cropImage(OriginalKey, width, height, left, top)
/**
* 크롭 이미지 이름을 결정한다.
*/
const Key = `Drawing/${objectNo}_${planNo}_${type}`
// Upload processed image
/**
* 크롭이 완료된 이미지를 업로드한다.
*/
await s3.send(
new PutObjectCommand({
Bucket,
@ -100,6 +110,9 @@ export async function POST(req) {
}),
)
/**
* 크롭이미지 저장이 완료되면 원본 이미지를 삭제한다.
*/
await s3.send(
new DeleteObjectCommand({
Bucket,