-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 나만의 생일 축하 카드 생성을 위한 presigned url 발급 API (#462)
- Loading branch information
Showing
13 changed files
with
126 additions
and
8 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
27 changes: 27 additions & 0 deletions
27
mashup-domain/src/main/java/kr/mashup/branding/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,27 @@ | ||
package kr.mashup.branding.config; | ||
|
||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import static com.amazonaws.regions.Region.getRegion; | ||
import static com.amazonaws.regions.Regions.*; | ||
|
||
@Configuration | ||
public class S3Config { | ||
|
||
@Value("${aws.s3.access-key}") | ||
private String accessKey; | ||
|
||
@Value("${aws.s3.secret-key}") | ||
private String secretKey; | ||
|
||
@Bean | ||
public AmazonS3Client amazonS3() { | ||
AmazonS3Client s3Client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey)); | ||
s3Client.setRegion(getRegion(AP_NORTHEAST_2)); | ||
return s3Client; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
mashup-domain/src/main/java/kr/mashup/branding/service/birthday/FileService.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,38 @@ | ||
package kr.mashup.branding.service.birthday; | ||
|
||
import com.amazonaws.HttpMethod; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.amazonaws.services.s3.Headers; | ||
import com.amazonaws.services.s3.model.CannedAccessControlList; | ||
import com.amazonaws.services.s3.model.GeneratePresignedUrlRequest; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.Instant; | ||
import java.util.Date; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FileService { | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
|
||
public String generatePresignedUrl(String bucket, String identifier, long expiresIn) { | ||
String fileName = createFileName(identifier); | ||
GeneratePresignedUrlRequest request = createPresignedUrlRequest(bucket, fileName, expiresIn); | ||
return amazonS3Client.generatePresignedUrl(request).toString(); | ||
} | ||
|
||
private GeneratePresignedUrlRequest createPresignedUrlRequest(String bucket, String filePath, long expiresIn) { | ||
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, filePath) | ||
.withMethod(HttpMethod.PUT) | ||
.withExpiration(Date.from(Instant.now().plusSeconds(expiresIn))); | ||
request.addRequestParameter(Headers.S3_CANNED_ACL, CannedAccessControlList.PublicRead.toString()); | ||
|
||
return request; | ||
} | ||
|
||
private String createFileName(String fileName) { | ||
return String.format("%d-%s", System.currentTimeMillis(), fileName); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
jwt: | ||
secretKey: ENC(EXfj1mGmsws/YLOc87IZoiHu0l+vKqtao+CrUR843UD0xWM9asYfSMWkYLI8CYQHlEeHwAh51Kt+/Zn8tS7n0g==) | ||
golden-danggn-percent: 1 | ||
golden-danggn-percent: 1 | ||
|
||
aws: | ||
s3: | ||
birthday: | ||
bucket-name: ENC(L67K3xOrB7AFVc42ntwiU30LIvXrQgBs3WL7rDEA68adLfqk1mNCgX8Vgi2k+r+KQWbMF4ukynROsDBRbdk0bA==) | ||
expires-in: 120 # 2 minutes |
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 |
---|---|---|
@@ -1,3 +1,9 @@ | ||
jwt: | ||
secretKey: ENC(EXfj1mGmsws/YLOc87IZoiHu0l+vKqtao+CrUR843UD0xWM9asYfSMWkYLI8CYQHlEeHwAh51Kt+/Zn8tS7n0g==) | ||
golden-danggn-percent: 1 | ||
golden-danggn-percent: 1 | ||
|
||
aws: | ||
s3: | ||
birthday: | ||
bucket-name: ENC(5wfapIYEplDWd9xav8HeC99yHvZKGzVbNfvAYu/G1dJmaD2Xj9B6YwPBGzF1pMcwb6jb5bF4AjlOTG9TM5ASBQ==) | ||
expires-in: 120 # 2 minutes |
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