이게 axios를 이용해서 서버로 전송하는 코드
export const imageSave = (files, config) => {
const request = axios.post('/api/post/image', files, config).then(res=>{
if(res.data.success){
return res.data.imgpaths
}else alert('파일을 불러올수 없습니다');
});
return{
type: IMAGE,
imgpaths: request
}
}
그리규 이게 서버에서 그거 처리해서 클라이언트로 보내주는 코드
router.post('/image', (req, res)=>{
upload(req, res, err=>{
if(err) return res.status(400).json({success: false, err});
else{
let imgpaths=[];
for(let i=0; i<req.files.length; i++){
imgpaths.push(req.files[i].path);
}
return res.status(200).json({success: true, imgpaths: imgpaths});
}
})
})
근데 콘솔에 찍어보면 imgpaths값이 이렇게 나옴
imgpaths
- Promise {<pending>}
- [[Prototype]]: Promise
- [[PromiseState]]: "fulfilled"
- [[PromiseResult]]: Array(2)
- 0: "images\1632562357496_7.jpg"
- 1: "images\1632562357499_8.jpg"
- length: 2
- [[Prototype]]: Array(0)
PromiseResult값 어떻게 꺼내쓰는지 모르겠슴 ㅠㅠ
어케함??????????????
then에 콜백 리턴값이 request 변수에 들어가지 않음
ㅜㅜㅜ
promiseResult는 몰겟다 request는 그냥 프로미스 객체가 할당댐 저였음 무지성으로 axios.post에 await 걸고 리스폰스값 가져옴
어떻게 해야 들어감?????????????????
상위 1% PromiseCapability, PromiseReaction 전문가
ㅎㅎ