-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from Tave-13th-Project-Team-4-Fiurinee/feature/S3
Feature/s3
- Loading branch information
Showing
4 changed files
with
76 additions
and
1 deletion.
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
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.example.fiurinee; | ||
|
||
import com.amazonaws.services.s3.AmazonS3; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import java.lang.String; | ||
|
||
import java.net.URL; | ||
|
||
@RestController | ||
public class S3Controller { | ||
|
||
private final AmazonS3 s3Client; | ||
private final String bucketName; | ||
|
||
public S3Controller(AmazonS3 s3Client, @Value("${AWS_BUCKET}") String bucketName) { | ||
this.s3Client = s3Client; | ||
this.bucketName = bucketName; | ||
} | ||
|
||
@GetMapping("/image") | ||
public ResponseEntity<URL> getImage(){ | ||
URL img = s3Client.getUrl(bucketName, "fiurinnn"); | ||
|
||
return ResponseEntity.ok(img); | ||
} | ||
} |
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,32 @@ | ||
package com.example.fiurinee; | ||
|
||
import com.amazonaws.auth.AWSCredentials; | ||
import com.amazonaws.auth.AWSStaticCredentialsProvider; | ||
import com.amazonaws.auth.BasicAWSCredentials; | ||
import com.amazonaws.services.s3.AmazonS3; | ||
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 StorageConfig { | ||
|
||
@Value("${AWS_ACCESSKEY}") | ||
private String accessKey; | ||
|
||
@Value("${AWS_SECRETKEY}") | ||
private String accessSecret; | ||
@Value("${cloud.aws.region.static}") | ||
private String region; | ||
|
||
@Bean | ||
public AmazonS3 s3Client() { | ||
AWSCredentials credentials = new BasicAWSCredentials(accessKey, accessSecret); | ||
return AmazonS3ClientBuilder.standard() | ||
.withCredentials(new AWSStaticCredentialsProvider(credentials)) | ||
.withRegion(region).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