-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from TaetaetaE01/main
각 도메인 세팅 수정 및 파일 타입 validate
- Loading branch information
Showing
12 changed files
with
145 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/bigbrotherbe/global/file/util/FileUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.bigbrotherbe.global.file.util; | ||
|
||
import com.example.bigbrotherbe.global.exception.BusinessException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import java.util.List; | ||
|
||
import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.INVALID_IMAGE_TYPE; | ||
import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.INVALID_PDF_TYPE; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class FileUtil { | ||
public void CheckImageFiles(List<MultipartFile> multipartFiles) { | ||
multipartFiles.stream() | ||
.filter(file -> { | ||
String contentType = file.getContentType(); | ||
return contentType == null || !(contentType.equals(MediaType.IMAGE_JPEG_VALUE) || | ||
contentType.equals("image/jpg") || | ||
contentType.equals(MediaType.IMAGE_PNG_VALUE) || | ||
contentType.equals(MediaType.IMAGE_GIF_VALUE)); | ||
}) | ||
.findFirst() | ||
.ifPresent(file -> { | ||
throw new BusinessException(INVALID_IMAGE_TYPE); | ||
}); | ||
} | ||
|
||
public void checkPdfFiles(List<MultipartFile> multipartFiles) { | ||
multipartFiles.stream() | ||
.filter(file -> { | ||
String contentType = file.getContentType(); | ||
return contentType == null || !contentType.equals(MediaType.APPLICATION_PDF_VALUE); | ||
}) | ||
.findFirst() | ||
.ifPresent(file -> { | ||
throw new BusinessException(INVALID_PDF_TYPE); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.