Skip to content

Commit

Permalink
Merge pull request #24 from seoshinehyo/feat/#23
Browse files Browse the repository at this point in the history
[Feat] 이미지 업로드 구현
  • Loading branch information
seoshinehyo authored Dec 19, 2024
2 parents 4e82351 + 557a399 commit 188d914
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies {
//env
implementation 'me.paulschwarz:spring-dotenv:3.0.0'

// AWS S3
implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4'
}

tasks.named('test') {
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/com/dearnote/config/AmazonConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.dearnote.config;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Getter
public class AmazonConfig {


private AWSCredentials awsCredentials;

@Value("${cloud.aws.credentials.access-key}")
private String accessKey;

@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;

@Value("${cloud.aws.region}")
private String region;

@PostConstruct
public void init() {
this.awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
}

@Bean
public AmazonS3 amazonS3() {
AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey);
return AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.build();
}

@Bean
public AWSCredentialsProvider awsCredentialsProvider() {
return new AWSStaticCredentialsProvider(awsCredentials);
}
}
3 changes: 3 additions & 0 deletions src/main/java/com/dearnote/domain/Image.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class Image extends BaseEntity {
@Column(nullable = true, columnDefinition = "VARCHAR(300)")
private String storeFileName;

@Column(nullable = true, columnDefinition = "VARCHAR(300)")
private String storeFileUrl;

private Integer size;

@OneToOne(fetch = FetchType.LAZY)
Expand Down
13 changes: 12 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ spring:
hibernate:
dialect: org.hibernate.dialect.MySQLDialect
hibernate:
ddl-auto: create
ddl-auto: create

cloud:
aws:
region: ap-northeast-2
credentials:
access-key: ${DEV_S3_ACCESS_KEY}
secret-key: ${DEV_S3_SECRET_KEY}
s3:
bucket: mybucket54
stack:
auto: false

0 comments on commit 188d914

Please sign in to comment.