diff --git a/backend/src/main/java/com/now/naaga/common/infrastructure/AwsS3Service.java b/backend/src/main/java/com/now/naaga/common/infrastructure/AwsS3Service.java index 28aaa955c..ceac20f48 100644 --- a/backend/src/main/java/com/now/naaga/common/infrastructure/AwsS3Service.java +++ b/backend/src/main/java/com/now/naaga/common/infrastructure/AwsS3Service.java @@ -1,10 +1,9 @@ package com.now.naaga.common.infrastructure; +import com.amazonaws.AmazonServiceException; import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3ClientBuilder; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.ObjectMetadata; -import com.amazonaws.services.s3.model.PutObjectRequest; +import com.amazonaws.services.s3.model.*; import com.now.naaga.common.exception.CommonException; import jakarta.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Value; @@ -13,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; import java.util.Objects; import java.util.UUID; @@ -43,6 +43,7 @@ public void setAmazonS3() { } public String uploadFile(final MultipartFile multipartFile) { + getObjectAcl(); validateFileExists(multipartFile); final String fileName = buildFileName(multipartFile.getOriginalFilename()); @@ -60,6 +61,20 @@ public String uploadFile(final MultipartFile multipartFile) { return amazonS3.getUrl(bucketName, fileName).toString(); } + private void getObjectAcl() { + try { + AccessControlList acl = amazonS3.getObjectAcl(bucketName, directory); + List grants = acl.getGrantsAsList(); + for (Grant grant : grants) { + System.out.format(" %s: %s\n", grant.getGrantee().getIdentifier(), + grant.getPermission().toString()); + } + } catch (AmazonServiceException e) { + System.err.println(e.getErrorMessage()); + System.exit(1); + } + } + private void validateFileExists(final MultipartFile multipartFile) { if (multipartFile.isEmpty()) { throw new IllegalArgumentException();