AWS S3 버킷 만들기
먼저 AWS S3버킷을 만들어줘야합니다!!
AWS S3 > 버킷 > 버킷 만들기
Spring 연결
1. build.gradle 의존성 추가
🔽 build.gradle
// AWS S3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
2. application.properties 추가
🔽 application.properties
# S3
cloud.aws.credentials.accessKey={발급받은 공개키}
cloud.aws.credentials.secretKey={발급받은 비밀키}
cloud.aws.s3.bucket={버킷명}
cloud.aws.region.static:ap-northeast-2
cloud.aws.stack.auto=false
3. S3 파일 생성
🔽 S3Config
@Configuration
public class S3Config {
@Value("${cloud.aws.credentials.accessKey}")
private String accessKey;
@Value("${cloud.aws.credentials.secretKey}")
private String secretKey;
@Value("${cloud.aws.region.static}")
private String region;
@Bean
public AmazonS3 amazonS3Client() {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
return AmazonS3ClientBuilder
.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(region)
.build();
}
}
4. S3 Manager만들기
multipartFile을 S3버킷에 저장해주는 S3 Manager을 만들어서 이미지 파일 관리!!
🔽 참고 블로그
[Spring] S3 이미지 업로드하기
사진, 동영상 등 파일을 저장하기 위해 사용하는 파일 서버 서비스. 일반적인 파일서버는 트래픽이 증가함에 따라서 장비를 증설하는 작업을 해야 하는데 S3는 이와 같은 것을 대행한다.
velog.io
'Spring' 카테고리의 다른 글
| [TIL] 240508 MongoDB 적용하기 | 채팅 DB MySQL에서 MongoDB로 변경 (0) | 2024.05.08 |
|---|---|
| [TIL] 240418 Spring Data JPA 페이징 및 정렬 | Pageable, PageableDefault (2) | 2024.04.18 |
| [TIL] 240412 즉시로딩, 지연로딩, 영속성 전이, OrphanRemoval (0) | 2024.04.12 |
| [TIL] 240409 Entity 연간 관계 | 1:1 매핑, 단방향, 양방향 (0) | 2024.04.09 |
| [TIL] 240408 RestTemplate | NaverOpenApi 검색 (0) | 2024.04.08 |