From 737443e97dce6fa7b75b76723d732c817343311a Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:08:07 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[=EA=B9=80=EC=A4=91=ED=98=84]=205=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EA=B3=BC=EC=A0=9C=20-=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../S3Controller.java" | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" new file mode 100644 index 0000000..212689d --- /dev/null +++ "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" @@ -0,0 +1,56 @@ +package ServerStudy5Cloud.ServerStudy5Cloud.Controller; + +import com.amazonaws.services.s3.AmazonS3; +import com.amazonaws.services.s3.model.*; +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.List; +import java.util.stream.Collectors; + +/** + * 영상 인증: https://drive.google.com/file/d/1aoKdLbbNA8EHkJmxeYoLGfrx0gwYSfdg/view?usp=sharing + */ +@Controller +@RequiredArgsConstructor +public class S3Controller { + + private final AmazonS3 amazonS3; + + @Value("${cloud.aws.s3.bucket}") + private String bucketName; + + @GetMapping("/") + public String listFiles(Model model) { + // 버킷의 object list 조회 + ObjectListing objectListing = amazonS3.listObjects(new ListObjectsRequest().withBucketName(bucketName)); + + // object list에서 각 object의 url을 조회해 list 생성 + List urls = objectListing.getObjectSummaries().stream() + .map(os -> amazonS3.getUrl(bucketName, os.getKey()).toString()) + .collect(Collectors.toList()); + model.addAttribute("urls", urls); // 모델에 추가해 뷰로 전달 + + return "index"; + } + + @PostMapping("/upload") + public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException { + // 전송한 파일 이름 조회 + String fileName = file.getOriginalFilename(); + + // 버킷에 파일 업로드 + amazonS3.putObject(new PutObjectRequest(bucketName, fileName, file.getInputStream(), null)); + // 파일의 접근 권한을 public으로 설정 + amazonS3.setObjectAcl(bucketName, fileName, CannedAccessControlList.PublicRead); + + return "redirect:/"; + } +} From 5fbb6a101b0ef2a5b9f5a61f867bd1da1ab39ab2 Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:09:00 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[=EA=B9=80=EC=A4=91=ED=98=84]=205=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EA=B3=BC=EC=A0=9C=20-=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../index.html" | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" new file mode 100644 index 0000000..592fda0 --- /dev/null +++ "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" @@ -0,0 +1,29 @@ + + + + + + + GDSC Server + + + +

AWS S3에 파일을 업로드해봐요!

+ +
+ + +
+ +

AWS S3의 파일을 확인해봐요!

+ + + + + +
+ +
+ + + From 9c2cb1aab7f18da97203cc7f93195629b2f9aad4 Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:09:50 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[=EA=B9=80=EC=A4=91=ED=98=84]=205=EC=A3=BC?= =?UTF-8?q?=EC=B0=A8=20=EA=B3=BC=EC=A0=9C=20-=20complete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application.yml" | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" new file mode 100644 index 0000000..5d08cb2 --- /dev/null +++ "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" @@ -0,0 +1,9 @@ +cloud: + aws: + s3: + bucket: gdsc-server-prac + stack.auto: false + region.static: ap-northeast-2 + credentials: + access-key: ${AWS_ACCESS_KEY} + secret-key: ${AWS_SECRET_KEY} From b0429ebb2422a4d38f2631314c82177987c0b0ac Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:13:58 +0900 Subject: [PATCH 4/6] Rename S3Controller.java to S3Controller_JoongHyunKim.java --- .../S3Controller_JoongHyunKim.java" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" => "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller_JoongHyunKim.java" (100%) diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller_JoongHyunKim.java" similarity index 100% rename from "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller.java" rename to "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/S3Controller_JoongHyunKim.java" From 152721f8fdc4a3aff81ac12f296ad8c786bb7af2 Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:14:16 +0900 Subject: [PATCH 5/6] Rename application.yml to application_JoongHyunKim.yml --- .../application_JoongHyunKim.yml" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" => "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application_JoongHyunKim.yml" (100%) diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application_JoongHyunKim.yml" similarity index 100% rename from "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application.yml" rename to "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/application_JoongHyunKim.yml" From de57a53fd7a661b714d49d23756a9c3347dfc1c0 Mon Sep 17 00:00:00 2001 From: JoongHyun Kim Date: Sat, 18 Nov 2023 19:14:31 +0900 Subject: [PATCH 6/6] Rename index.html to index_JoongHyunKim.html --- .../index_JoongHyunKim.html" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" => "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index_JoongHyunKim.html" (100%) diff --git "a/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" "b/5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index_JoongHyunKim.html" similarity index 100% rename from "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index.html" rename to "5\354\243\274\354\260\250 Server S-Day \352\263\274\354\240\234/index_JoongHyunKim.html"