• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

안녕하세요 선생님.

21.02.06 00:26 작성 조회수 85

0

aws s3에 사진을 업로드 하는 것 까지는 완료 했는데 버킷에서 사진을 어떻게 불러와야 할 지 모르겠습니다. 

아래 처럼 해서 s3에 업로드는 되는데 console을 찍어 본 결과 res.req.file이 undefined 결과로 나옵니다 ㅠ

const storage = multerS3({
s3: s3,
bucket: 'my-app',
acl: 'public-read-write',
metadata: function (req, file, cb) {
cb(null, { fieldName: file.fieldname });
},
key: function (req, file, cb) {
cb(null, Date.now().toString())
},
})

var upload = multer({ storage: storage }).single("file")

router.post('/image', (req, res) => {
//가져온 이미지를 저장을 해주면 된다.
upload(req, res, err => {//가져온 이미지를 저장하기.
if (err) {//프론트엔드로 정보 전달
return req.json({ success: false, err })
}
console.log(res.req.file)
return res.json({ success: true, filePath: res.req.file.path, fileName: res.req.file.filename })
})
})

답변 0

답변을 작성해보세요.

답변을 기다리고 있는 질문이에요.
첫번째 답변을 남겨보세요!