diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/S3Controller.java" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/S3Controller.java" deleted file mode 100644 index c08ae6e..0000000 --- "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/S3Controller.java" +++ /dev/null @@ -1,53 +0,0 @@ -package ServerStudy5Cloud.ServerStudy5Cloud.Controller; - -import com.amazonaws.services.s3.AmazonS3; -import com.amazonaws.services.s3.model.CannedAccessControlList; -import com.amazonaws.services.s3.model.S3ObjectSummary; -import lombok.RequiredArgsConstructor; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.multipart.MultipartFile; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - - -@Controller -@RequiredArgsConstructor -public class S3Controller { - - private final AmazonS3 amazonS3; - - @Value("${cloud.aws.s3.bucket}") - private String bucketName; - - @GetMapping("/") - public String listFiles(Model model) { - // S3 버킷의 객체 목록 가져오기 - List objectSummaries = amazonS3.listObjectsV2(bucketName).getObjectSummaries(); - // getUrl로 객체 URL 가져온 후, List에 넣어 index.html에 반환 - List fileUrls = new ArrayList<>(); - for (S3ObjectSummary os : objectSummaries) { - String url = amazonS3.getUrl(bucketName, os.getKey()).toString(); - fileUrls.add(url); - } - model.addAttribute("fileUrls", fileUrls); - return "index"; - } - - @PostMapping("/upload") - public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException { - String filename = file.getOriginalFilename(); - // putObject로 파일을 S3 버킷에 업로드 - amazonS3.putObject(bucketName, filename, file.getInputStream(), null); - // ACL 퍼블릭으로 설정 - amazonS3.setObjectAcl(bucketName, filename, CannedAccessControlList.PublicRead); - return "redirect:/"; - } -} -// 동작 영상 : https://drive.google.com/file/d/10wPjsBbnbIR5E6pKbwmr2sZ-GsLY-FWP/view?usp=sharing \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/application.yml" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/application.yml" deleted file mode 100644 index 4b7489c..0000000 --- "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/files_leeseohyun/application.yml" +++ /dev/null @@ -1,15 +0,0 @@ -spring: - config: - import: optional:file:.env[.properties] -# 이렇게 .env 파일을 사용하려고 했지만 잘 동작하지 않아서... 빌드 Edit Configuration에서 Environment variables로 설정해서 했습니다...! -cloud: - aws: - s3: - bucket: ${S3_BUCKET} - stack.auto: false - region.static: ap-northeast-2 - credentials: - access-key: ${CREDENTIALS_ACCESS_KEY} - secret-key: ${CREDENTIALS_SECRET_KEY} -server: - port: 8080 \ No newline at end of file diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/\354\235\264\354\204\234\355\230\204_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/\354\235\264\354\204\234\355\230\204_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" deleted file mode 100644 index fa3f376..0000000 --- "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/\354\235\264\354\204\234\355\230\204_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" +++ /dev/null @@ -1,11 +0,0 @@ -### 5주차 Server S-Day 과제 - 이서현 -> 과제: S3에 객체 업로드 및 조회 - -> 심화 과제: application.yml 변경 - -## 과제 -### 사진 -![image](https://github.com/GDSC-Ewha-5th/GDSC-Server-5th/assets/32611398/305cc543-d0df-46bc-8c28-d615a45a70fa) - -### 참고 자료 -* [Spring] 설정 파일 환경변수를 통해 숨기기 — Shin._.Mallang https://ttl-blog.tistory.com/1125