-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from mju-likelion/feature/s3-config-#65
Feature/#65 S3 설정 추가
- Loading branch information
Showing
6 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/mutsideout_mju/config/S3Config.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.example.mutsideout_mju.config; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class S3Config { | ||
@Value("${cloud.aws.credentials.accessKey}") | ||
private String accessKey; | ||
@Value("${cloud.aws.credentials.secretKey}") | ||
private String secretKey; | ||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3Client() { | ||
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); | ||
|
||
return (AmazonS3Client) AmazonS3ClientBuilder.standard() | ||
.withRegion(region) | ||
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/example/mutsideout_mju/util/S3Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.mutsideout_mju.util; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* AWS S3 관련된 기능 구현 | ||
* 업로드, 조회 | ||
*/ | ||
@Service | ||
@RequiredArgsConstructor | ||
public class S3Service { | ||
private final AmazonS3 s3client; | ||
@Value("${cloud.aws.s3.bucket-name}") | ||
private String bucketName; | ||
|
||
public String getRoomImageLink(String link) { | ||
String imagePath = getImagePath(link); | ||
return imagePath != null ? generateFileUrl(imagePath) : null; | ||
} | ||
|
||
private String generateFileUrl(String key) { | ||
return s3client.getUrl(bucketName.trim(), key).toString(); | ||
} | ||
|
||
private String getImagePath(String link) { | ||
String basePath = "rooms/"; | ||
if (link.contains("google")) { | ||
return basePath + "googlemeet.svg"; | ||
} else if (link.contains("zoom")) { | ||
return basePath + "zoom.svg"; | ||
} else if (link.contains("discord")) { | ||
return basePath + "discord.svg"; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |