-
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.
- Loading branch information
1 parent
5da57cb
commit 1a00342
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
meongcare/src/main/java/com/meongcare/domain/file/s3/application/PreSignedUrlService.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,36 @@ | ||
package com.meongcare.domain.file.s3.application; | ||
|
||
import com.amazonaws.HttpMethod; | ||
import com.amazonaws.services.s3.AmazonS3Client; | ||
import com.meongcare.domain.file.s3.presentation.dto.response.PreSignedUrlResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PreSignedUrlService { | ||
|
||
@Value("${cloud.aws.s3.bucket}") | ||
private String bucket; | ||
|
||
private final AmazonS3Client amazonS3Client; | ||
|
||
public PreSignedUrlResponse getPreSignedUrl(String fileName) { | ||
Calendar now = Calendar.getInstance(); | ||
now.add(Calendar.MINUTE, 3); | ||
|
||
Date expiration = now.getTime(); | ||
|
||
String preSignedUrl = amazonS3Client.generatePresignedUrl(bucket, fileName, expiration, HttpMethod.PUT) | ||
.toString(); | ||
return new PreSignedUrlResponse(preSignedUrl); | ||
} | ||
|
||
public void updateImageLink(String imageUrl) { | ||
|
||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
meongcare/src/main/java/com/meongcare/domain/file/s3/presentation/AwsS3Controller.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,30 @@ | ||
package com.meongcare.domain.file.s3.presentation; | ||
|
||
import com.meongcare.domain.file.s3.application.PreSignedUrlService; | ||
import com.meongcare.domain.file.s3.presentation.dto.response.PreSignedUrlResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PatchMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/aws/s3") | ||
public class AwsS3Controller { | ||
|
||
private final PreSignedUrlService preSignedUrlService; | ||
|
||
@GetMapping | ||
public ResponseEntity<PreSignedUrlResponse> getPreSignedUrl(@RequestParam String fileName) { | ||
return ResponseEntity.ok(preSignedUrlService.getPreSignedUrl(fileName)); | ||
} | ||
|
||
@PatchMapping | ||
public ResponseEntity<Void> updateImageLink(@RequestParam String imageUrl) { | ||
preSignedUrlService.updateImageLink(imageUrl); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ain/java/com/meongcare/domain/file/s3/presentation/dto/response/PreSignedUrlResponse.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,10 @@ | ||
package com.meongcare.domain.file.s3.presentation.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PreSignedUrlResponse { | ||
private String preSignedUrl; | ||
} |