Skip to content

Commit

Permalink
Merge pull request #9 from Tave-13th-Project-Team-4-Fiurinee/feature/S3
Browse files Browse the repository at this point in the history
Feature/s3
  • Loading branch information
ss7622 authored May 25, 2024
2 parents 5dd35ec + 6e83900 commit aa45343
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/example/fiurinee/S3Controller.java
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);
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/example/fiurinee/StorageConfig.java
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();
}

}

14 changes: 13 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,16 @@ spring:

logging.level:
org.hibernate.SQL: debug
org.hibernate.type: trace
org.hibernate.type: trace

cloud:
aws:
credentials:
accessKey: ${AWS_ACCESSKEY}
secretKey: ${AWS_SECRETKEY}
s3:
bucket: ${AWS_BUCKET}
region:
static: ap-northeast-2
stack:
auto: 'false'

0 comments on commit aa45343

Please sign in to comment.