• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 이미지 업로드 기능 만들기 2강 오류

이미지 업로드 기능 만들기 2강 오류

4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 글쓴이
  • #124411

    진하경
    참가자
    제목 없음-1
    
    
    
    // aws
    const { S3Client } = require('@aws-sdk/client-s3')
    const multer = require('multer')
    const multerS3 = require('multer-s3')
    const s3 = new S3Client({
      region : 'ap-northeast-2',
      credentials : {
          accessKeyId : '키111',
          secretAccessKey : '시크릿키 받아씀'
      }
    })
    const upload = multer({
      storage: multerS3({
        s3: s3,
        bucket: '제 버킷 계정 썼어요',
        key: function (요청, file, cb) {
          cb(null, Date.now().toString()) //업로드시 파일명 변경가능
        }
      })
    })
    
    
    //글 작성 기능
    app.post("/add",async(요청,응답)=>{
      upload.single('img')(요청,응답,async(err)=>{
        if(err) return 응답.send("업로드 에러")
          try{
            if(요청.body==""){
              응답.send("비어있음")
            }else{
            await db.collection('post').insertOne({title:요청.body.title,
              content:요청.body.content,img:요청.file.location});
            응답.redirect("/nellkenny")}
          }catch(e){
            console.log(e)
            응답.state(500).send("서버 에러남")
          }
      })
    })
    
    이렇게 짰는데 저런 오류가 계속납니다.
    미들웨어대신에 해도 오류가 나고 있어요...
    aws키를 로컬로 설정해서 했는데 혹시 다른 방법으로 키를 받아야 하나요?
    
    
    
    #124422

    codingapple
    키 마스터
    응답 파라미터가 2개인데 하나는 다른걸로 작명해봅시다
    #124580

    진하경
    참가자
    말씀하신대로
    app.post("/add",async(요청,응답)=>{
      upload.single('img')(요청,응답2,async(err)=>{
        if(err) return 응답2.send("업로드 에러")
          try{
            if(요청.body==""){
              응답.send("비어있음")
            }else{
            await db.collection('post').insertOne({title:요청.body.title,
              content:요청.body.content,img:요청.file.location});
            응답.redirect("/nellkenny")}
          }catch(e){
            console.log(e)
            응답.state(500).send("서버 에러남")
          }
      })
    })로 응답2로 수정을 했으나
    D:\study\codingApple\node\server.js:80
      upload.single('img')(요청,응답2,async(err)=>{
    ess\lib\router\route.js:114:3)
        at Layer.handle [as handle_request] (D:\study\codingApple\node\node_modules\express\lib\router\layer.js:95:5)
        at D:\study\codingApple\node\node_modules\express\lib\router\index.js:284:15
        at Function.process_params (D:\study\codingApple\node\node_modules\express\lib\router\index.js:346:12)
        at next (D:\study\codingApple\node\node_modules\express\lib\router\index.js:280:10)
        at strategy.pass (D:\study\codingApple\node\node_modules\passport\lib\middleware\authenticate.js:355:9)
        at SessionStrategy.authenticate (D:\study\codingApple\node\node_modules\passport\lib\strategies\session.js:126:10)
    
    라는 오류가 계속 뜨고 있습니다.
    이미지를 넣지않고 보내보려고 file 타입 input은 제외 후 멀티파트만 유지한채 보내봐도 오류가 계속해서 뜨고 있습니다.
    #124593

    codingapple
    키 마스터
    아니네요 그냥 응답.state()가 오타였나봅니다
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠