Skip to content

Commit

Permalink
feat: png / jpg 파일만 입력 가능하도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ehs208 committed Oct 19, 2024
1 parent 11b24ff commit 12cd7b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.leets.xcellentbe.domain.user.exception;

import com.leets.xcellentbe.global.error.ErrorCode;
import com.leets.xcellentbe.global.error.exception.CommonException;

public class InvalidFileFormat extends CommonException {
public InvalidFileFormat() {
super(ErrorCode.INVALID_FILE_FORMAT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.PutObjectRequest;
import com.leets.xcellentbe.domain.user.exception.InvalidFileFormat;
import com.leets.xcellentbe.global.error.exception.custom.InternalServerErrorException;

import lombok.RequiredArgsConstructor;
Expand All @@ -28,6 +29,11 @@ public class S3UploadService {

// MultipartFile을 전달받아 File로 전환한 후 S3에 업로드
public String upload(MultipartFile multipartFile, String dirName) { // dirName의 디렉토리가 S3 Bucket 내부에 생성됨
String fileName = multipartFile.getOriginalFilename();
if ((fileName.endsWith(".png") || fileName.endsWith(".jpg"))) {
throw new InvalidFileFormat();
}

try {
File uploadFile = convert(multipartFile).
orElseThrow(() -> new RuntimeException());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
public enum ErrorCode {

INVALID_INPUT_VALUE(400, "INVALID_INPUT_VALUE", "유효하지 않은 입력값입니다."),
INVALID_FILE_FORMAT(400, "INVALID_FILE_FORMAT", "올바르지 않은 파일 형식입니다."),
INVALID_TOKEN(401, "INVALID_TOKEN", "유효하지 않은 토큰입니다."),
LOGIN_FAIL(401, "LOGIN_FAIL", "로그인에 실패하였습니다."),
CHAT_ROOM_FORBIDDEN(403, "CHAT_ROOM_FORBIDDEN","권한이 없는 채팅방입니다."),
Expand Down

0 comments on commit 12cd7b4

Please sign in to comment.