88import software .amazon .awssdk .regions .Region ;
99import software .amazon .awssdk .services .s3 .S3Client ;
1010
11+ import java .net .URI ;
12+
1113@ Configuration
1214public class S3Config {
1315
16+ // AWS S3 Configuration (for AI buckets)
1417 @ Value ("${aws.s3.region}" )
1518 private String region ;
1619
@@ -20,23 +23,51 @@ public class S3Config {
2023 @ Value ("${aws.secret-key}" )
2124 private String secretKey ;
2225
23- @ Value ("${aws.s3.static.bucket}" )
24- private String staticBucketName ;
25-
2626 @ Value ("${aws.s3.ai.input.bucket}" )
2727 private String aiInputBucketName ;
2828
2929 @ Value ("${aws.s3.ai.output.bucket}" )
3030 private String aiOutputBucketName ;
3131
32+ // Cloudflare R2 Configuration (for Static files)
33+ @ Value ("${cf.r2.endpoint}" )
34+ private String r2Endpoint ;
35+
36+ @ Value ("${cf.r2.access-key}" )
37+ private String r2AccessKey ;
38+
39+ @ Value ("${cf.r2.secret-key}" )
40+ private String r2SecretKey ;
41+
42+ @ Value ("${cf.r2.static.bucket}" )
43+ private String r2StaticBucketName ;
44+
45+ /**
46+ * AWS S3 클라이언트 (AI Input/Output 버킷용)
47+ */
3248 @ Bean ("s3AiClient" )
3349 public S3Client s3AiClient () {
34- return createS3Client ();
50+ AwsBasicCredentials credentials = AwsBasicCredentials .create (accessKey , secretKey );
51+
52+ return S3Client .builder ()
53+ .region (Region .of (region ))
54+ .credentialsProvider (StaticCredentialsProvider .create (credentials ))
55+ .build ();
3556 }
3657
58+ /**
59+ * Cloudflare R2 클라이언트 (Static 파일용)
60+ * R2는 S3 호환 API를 제공하므로 endpoint만 변경하면 됩니다.
61+ */
3762 @ Bean ("s3StaticClient" )
3863 public S3Client s3StaticClient () {
39- return createS3Client ();
64+ AwsBasicCredentials credentials = AwsBasicCredentials .create (r2AccessKey , r2SecretKey );
65+
66+ return S3Client .builder ()
67+ .endpointOverride (URI .create (r2Endpoint ))
68+ .region (Region .of ("auto" )) // R2는 auto region 사용
69+ .credentialsProvider (StaticCredentialsProvider .create (credentials ))
70+ .build ();
4071 }
4172
4273 @ Bean ("aiInputBucketName" )
@@ -51,15 +82,6 @@ public String aiOutputBucketName() {
5182
5283 @ Bean ("staticBucketName" )
5384 public String staticBucketName () {
54- return staticBucketName ;
55- }
56-
57- private S3Client createS3Client () {
58- AwsBasicCredentials credentials = AwsBasicCredentials .create (accessKey , secretKey );
59-
60- return S3Client .builder ()
61- .region (Region .of (region ))
62- .credentialsProvider (StaticCredentialsProvider .create (credentials ))
63- .build ();
85+ return r2StaticBucketName ;
6486 }
6587}
0 commit comments