4 글 보임 - 1 에서 4 까지 (총 4 중에서)
-
글쓴이글
-
2024년 5월 28일 23:33 #124411
진하경참가자// 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키를 로컬로 설정해서 했는데 혹시 다른 방법으로 키를 받아야 하나요?
2024년 5월 30일 22:24 #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은 제외 후 멀티파트만 유지한채 보내봐도 오류가 계속해서 뜨고 있습니다.
-
글쓴이글
4 글 보임 - 1 에서 4 까지 (총 4 중에서)
- 답변은 로그인 후 가능합니다.