Skip to content

Commit

Permalink
feat: 프로필 이미지 사이즈 2MB 제한
Browse files Browse the repository at this point in the history
  • Loading branch information
goathoon committed Oct 11, 2023
1 parent 86c5c5f commit e83b932
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
@Service
@RequiredArgsConstructor
public class MemberService {

private final TokenProvider tokenProvider;
@Value("${jwt.domain}") private String domain;

Expand Down Expand Up @@ -180,6 +181,8 @@ private IsProfileSavedDto createMemberProfileWithoutImage(Long userId, MemberInf

private IsProfileSavedDto createMemberProfileWithImage(Long userId, MemberInfoDto memberInfoDto) {
MultipartFile memberProfileImage = memberInfoDto.getImage();
checkImageSize(memberProfileImage);

String imageName = S3Utils.generateImageNameOfS3(memberInfoDto, userId);

checkAlreadyExists(userId);
Expand All @@ -192,6 +195,11 @@ private IsProfileSavedDto createMemberProfileWithImage(Long userId, MemberInfoDt

}

private void checkImageSize(MultipartFile image){
if (image.getSize() > S3Utils.MAX_PROFILE_IMAGE_SIZE){
throw new BadRequestException("프로필 이미지 사이즈는 2MB 이하로 등록 가능합니다.");
}
}
private void checkAlreadyExists(Long userId) {
if(!Optional.ofNullable(myRepository.findProfileImageNameById(userId)).isEmpty()){
throw new BadRequestException("이미 존재하는 프로필정보를 최초 저장하는 이슈. -> Patch로 전송바람");
Expand Down Expand Up @@ -223,6 +231,8 @@ else if(priorImageName.isPresent()){

private IsProfileSavedDto updateMemberProfileWithImage(Long userId, MemberInfoDto memberInfoDto) {
MultipartFile memberProfileImage = memberInfoDto.getImage();
checkImageSize(memberProfileImage);

String imageName = S3Utils.generateImageNameOfS3(memberInfoDto, userId);

Optional<String> priorImageName = Optional.ofNullable(myRepository.findProfileImageNameById(userId));
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/Funssion/Inforum/s3/S3Utils.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package Funssion.Inforum.s3;

import Funssion.Inforum.domain.member.dto.request.MemberInfoDto;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.model.ObjectMetadata;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.net.URL;
import java.util.UUID;

public abstract class S3Utils{

public static final int MAX_PROFILE_IMAGE_SIZE = 2_097_152;
public static ObjectMetadata getObjectMetaData(MultipartFile file){
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentType(file.getContentType());
Expand Down

0 comments on commit e83b932

Please sign in to comment.