• 카테고리

    질문 & 답변
  • 세부 분야

    풀스택

  • 해결 여부

    미해결

질문드립니다.

22.03.07 16:35 작성 조회수 127

0

document.getElementById('img').addEventListener('change', function(e) {
        const formData = new FormData();
        console.log(this, this.files);
        formData.append('img', this.files[0]);
        console.log(formData);
        axios.post('/post/img', formData)
          .then((res) => {
            document.getElementById('img-url').value = res.data.url;
            document.getElementById('img-preview').src = res.data.url;
            document.getElementById('img-preview').style.display = 'inline';
          })
          .catch((err) => {
            console.error(err);
          });
    });
 
1 . formdata를 axios 하기전에 어떤 데이터를 가지고있나 보고싶은데
실질적인 데이터는 어떻게 확인이 가능할까요?
append시켜서 추가시킨 files[0]은 어디에 있는지 찾아도 안보여서 질문드립니다.
 
router.post('/', isLoggedIn, upload2.none(), async (req, res, next) => {
  try {
    const post = await Post.create({
      content: req.body.content,
      img: req.body.url,
      UserId: req.user.id,
  });
 
 
2. 그리고 중간에 upload.none() 을 안써주면 애러가 나던데
upload2 미들웨어를 실행해야지만 req.body에 데이터가 들어가는건가요?
 
 
3. 넌적스에서 예를들어 console.log() 자바스크립트 문법처럼
render로 넘긴 데이터가 객체일때 넌적스나 html 반복문 돌리기전에 데이터를 확인하는 방법이 없나요? {{twit}}로만하면
[object SequelizeInstance:Post]라고만 나와서요

답변 1

답변을 작성해보세요.

0

1. 못봅니다.

2. multipart 데이터라서 multer가 꼭 있어야합니다.

3.라우터에서 확인하셔야 합니다.