Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 이미지 업로드 구현 #24

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: 이미지 업로드 구현
seoshinehyo committed Dec 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8cd0d3c8e8c037db5f86d3058bccc526ceaf4c48
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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') {
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
@@ -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)
13 changes: 12 additions & 1 deletion src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
@@ -16,4 +16,15 @@ spring:
use_sql_comments: true
hbm2ddl:
auto: update
default_batch_fetch_size: 1000
default_batch_fetch_size: 1000

cloud:
aws:
region: ap-northeast-2
credentials:
access-key: ${DEV_S3_ACCESS_KEY}
secret-key: ${DEV_S3_SECRET_KEY}
s3:
bucket: beat-dev-bucket
stack:
auto: false
13 changes: 12 additions & 1 deletion src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -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