Skip to content

Commit

Permalink
feat: S3테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
zillionme committed Oct 9, 2023
1 parent e64cc04 commit ea20bbd
Showing 1 changed file with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +12,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -43,6 +43,7 @@ public void setAmazonS3() {
}

public String uploadFile(final MultipartFile multipartFile) {
getObjectAcl();
validateFileExists(multipartFile);

final String fileName = buildFileName(multipartFile.getOriginalFilename());
Expand All @@ -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<Grant> 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();
Expand Down

0 comments on commit ea20bbd

Please sign in to comment.