From 8cd64b8bacf377b254185996ce72c53dee4a4f4b Mon Sep 17 00:00:00 2001 From: Dongseon Yang <78548833+dongseon0@users.noreply.github.com> Date: Fri, 17 Nov 2023 23:07:28 +0900 Subject: [PATCH] =?UTF-8?q?Delete=205=EC=A3=BC=EC=B0=A8=20Sever=20S-Day=20?= =?UTF-8?q?directory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../S3Controller.java" | 66 ------------------- ...4\354\260\250_\352\263\274\354\240\234.md" | 11 ---- 2 files changed, 77 deletions(-) delete mode 100644 "5\354\243\274\354\260\250 Sever S-Day/S3Controller.java" delete mode 100644 "5\354\243\274\354\260\250 Sever S-Day/\354\226\221\353\217\231\354\204\240_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" diff --git "a/5\354\243\274\354\260\250 Sever S-Day/S3Controller.java" "b/5\354\243\274\354\260\250 Sever S-Day/S3Controller.java" deleted file mode 100644 index 9e54923..0000000 --- "a/5\354\243\274\354\260\250 Sever S-Day/S3Controller.java" +++ /dev/null @@ -1,66 +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.ObjectMetadata; -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; - -//영상 링크 : https://drive.google.com/file/d/17tmgRlWb4g0ZRuUKt6pvBlmmw-NqpDHR/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) { - List fileUrls = new ArrayList<>(); - List objectSummaries = amazonS3.listObjects(bucketName).getObjectSummaries(); - // 객체 URL을 리스트에 추가 - for (S3ObjectSummary objectSummary : objectSummaries) { - fileUrls.add(amazonS3.getUrl(bucketName, objectSummary.getKey()).toString()); - } - // 모델에 URL 리스트 추가 - model.addAttribute("fileUrls", fileUrls); - return "index"; - } - - @PostMapping("/upload") - public String uploadFile(@RequestParam("file") MultipartFile file) { - try { - /// ObjectMetadata 인스턴스 생성 - ObjectMetadata metadata = new ObjectMetadata(); - - // content type (MIME type)세팅 - metadata.setContentType(file.getContentType()); - - // S3에 파일 업로드 - amazonS3.putObject(bucketName, file.getOriginalFilename(), file.getInputStream(), metadata); - - // ACL를 public-read로 - amazonS3.setObjectAcl(bucketName, file.getOriginalFilename(), CannedAccessControlList.PublicRead); - - - return "redirect:/"; - } catch (IOException e) { - // Handle the exception appropriately (e.g., log it or show an error message) - return "error"; - } - - } -} diff --git "a/5\354\243\274\354\260\250 Sever S-Day/\354\226\221\353\217\231\354\204\240_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" "b/5\354\243\274\354\260\250 Sever S-Day/\354\226\221\353\217\231\354\204\240_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" deleted file mode 100644 index f9ed048..0000000 --- "a/5\354\243\274\354\260\250 Sever S-Day/\354\226\221\353\217\231\354\204\240_5\354\243\274\354\260\250_\352\263\274\354\240\234.md" +++ /dev/null @@ -1,11 +0,0 @@ -## 과정 -1. 인스턴스 생성(EC2) -2. 보안자격증명 > 키 생성 -3. index.html과 S3Controller 파일 수정 -4. main 메소드를 실행한 후 결과 확인 ! - -## 난관 -해결 : test를 돌리는데 안돼서 당황했지만, 코어멤버 혜승님께서 main 메소드를 돌리는 것을 알려주셨다!! 서비스를 구동하려면 main메소드를 돌리는 것이구나.. - -귀여운 미리보기 -스크린샷 2023-11-17 오후 10 54 53