Server&load/AWS

S3 를 활용해 Express 서버에 이미지 업로드 기능 구현하기

몽자비루 2025. 5. 6. 20:50
  1. IDE 에서 기존에 가지고 있던 프로젝트 열기
    1. node app.js 로 서버 실행하기
    2. postman 에서 파일 업로드하기

      • localhost:80/upload 로 URL 주소 입력하기.
      • Body에 form-data 형식으로, file 추가한 뒤 Send 선택
      • Response body(8) 에서 location 은 S3 가 보내준 이미지 파일 위치
    3. 버킷에 올라가있는 지 확인
      • AWS 의 S3 에서 이미지가 올라온것을 확인할 수 있다.
      • 객체 url을 선택하면 해당 파일을 다운로드 진행할 수 있다.
    4. S3에 저장된 URL로 이미지 잘 조회되는 지 확인
      • 아래 코드에서 img src 내부에 값 입력하기
        <!doctype html>
        <html lang="en">
        <head>
          <meta charset="UTF-8">
          <meta name="viewport"
                content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
          <meta http-equiv="X-UA-Compatible" content="ie=edge">
          <title>Document</title>
        </head>
        <body>
          <h1>이미지 테스트</h1>
          <img src="______"/>
        </body>
        </html>
      • 웹 페이지에서 해당 html 확인하기