Skip to content

Commit 6d3a862

Browse files
authored
Merge pull request #68 from rhkr8521/refac/#change-bucket-server
[REFAC] S3 버킷 서버 변경
2 parents fde5fbc + dd2e4af commit 6d3a862

File tree

3 files changed

+67
-11
lines changed

3 files changed

+67
-11
lines changed

src/main/java/com/rhkr8521/mapping/api/aws/s3/S3Service.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public List<String> uploadMemoImages(String userIdentifier, List<MultipartFile>
5858
.build();
5959

6060
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
61-
imageUrls.add(domain + "/" + fileKey);
61+
// AWS S3
62+
//imageUrls.add(domain + "/" + fileKey);
63+
// rhkr8521-Bucket
64+
imageUrls.add(domain + "/" + bucketName + "/" + fileKey);
6265
}
6366

6467
return imageUrls;
@@ -87,12 +90,19 @@ public String uploadProfileImage(String email, MultipartFile file) throws IOExce
8790
.acl("public-read")
8891
.build();
8992
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(file.getInputStream(), file.getSize()));
90-
return domain + "/" + fileKey;
93+
// AWS S3
94+
//return domain + "/" + fileKey;
95+
// rhkr8521-Bucket
96+
return domain + "/" + bucketName + "/" + fileKey;
97+
9198
}
9299

93100
public void deleteFile(String imageUrl) {
94101
if (imageUrl != null && imageUrl.startsWith(domain)) {
95-
String fileKey = imageUrl.replace(domain + "/", "");
102+
// AWS S3
103+
//String fileKey = imageUrl.replace(domain + "/", "");
104+
// rhkr8521-Bucket
105+
String fileKey = imageUrl.replace(domain + "/" + bucketName + "/", "");
96106
DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder()
97107
.bucket(bucketName)
98108
.key(fileKey)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.rhkr8521.mapping.common.config.aws;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
7+
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
8+
import software.amazon.awssdk.regions.Region;
9+
import software.amazon.awssdk.services.s3.S3Client;
10+
import software.amazon.awssdk.services.s3.S3Configuration;
11+
12+
import java.net.URI;
13+
14+
@Configuration
15+
public class MinioConfig {
16+
17+
@Value("${cloud.aws.credentials.accessKey}")
18+
private String accessKey;
19+
20+
@Value("${cloud.aws.credentials.secretKey}")
21+
private String secretKey;
22+
23+
@Value("${cloud.aws.region.static}")
24+
private String region;
25+
26+
@Value("${cloud.aws.s3.domain}")
27+
private String minioEndpoint;
28+
29+
@Bean
30+
public S3Client s3Client() {
31+
S3Configuration s3Configuration = S3Configuration.builder()
32+
.pathStyleAccessEnabled(true)
33+
.build();
34+
35+
return S3Client.builder()
36+
.credentialsProvider(
37+
StaticCredentialsProvider.create(
38+
AwsBasicCredentials.create(accessKey, secretKey)
39+
)
40+
)
41+
.region(Region.of(region))
42+
.endpointOverride(URI.create(minioEndpoint))
43+
.serviceConfiguration(s3Configuration)
44+
.build();
45+
}
46+
}

src/main/java/com/rhkr8521/mapping/common/config/aws/S3Config.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class S3Config {
2020
@Value("${cloud.aws.region.static}")
2121
private String region;
2222

23-
@Bean
24-
public S3Client s3Client() {
25-
AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKey, secretKey);
26-
return S3Client.builder()
27-
.region(Region.of(region))
28-
.credentialsProvider(StaticCredentialsProvider.create(awsCreds))
29-
.build();
30-
}
23+
// @Bean
24+
// public S3Client s3Client() {
25+
// AwsBasicCredentials awsCreds = AwsBasicCredentials.create(accessKey, secretKey);
26+
// return S3Client.builder()
27+
// .region(Region.of(region))
28+
// .credentialsProvider(StaticCredentialsProvider.create(awsCreds))
29+
// .build();
30+
// }
3131
}

0 commit comments

Comments
 (0)