Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[박규성] Create 서버로 사진파일과 객체 전송하기 #1124

Merged
merged 1 commit into from Nov 7, 2022

Conversation

guesung
Copy link
Contributor

@guesung guesung commented Nov 1, 2022

No description provided.

@guesung guesung added 6주차 프론트 블로그포스팅-프론트 9기 labels Nov 1, 2022
@pkch93 pkch93 added 7주차 and removed 6주차 labels Nov 3, 2022
@pkch93 pkch93 requested review from pkch93 and JangAyeon and removed request for pkch93 November 3, 2022 11:08
method: 'POST',
url: `주소/api/user/signup`,
headers: {
'Content-Type': 'multipart/form-data',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 규성님

작업환경에서 axios 버전이 궁금합니다! 제가 알기로는 axios 0.27 이후 버전에서는
Content-Type이 multipart/form-data 일때 application/x-www-form-urlencoded 으로 변환되어서 갑니다.

해당 이슈는 axios github에서도 논의된적 있습니다.
axios/axios#4627

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

버전 0.27.2입니다 !!
앗 정말요 multipart/form-data로 전송할 경우 문제가 있는걸까요 ???

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이후 글을 읽어보니 0.27 때 hotfix로 고쳐졌고

하지만 2주전 릴리즈된 1.1.3 에서 또 발생한다고 하네요

);
};
```
그런데, 백엔드 서버측에서 proxy-middleware까지 요구하지 않는 경우, setupProxy.js 파일로 인해 500오류가 계속 발생할 수 있습니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

백엔드 서버에서 proxy-middleware를 요구하지 않는다는 의미가 어떤걸까요?? 이부분은 잘 이해가 되지 않네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음 ,, http-proxy-middleware 패키지를 설치하고 그에 따라서 setUpProxy.js 파일을 만들어서 오류가 떠서 저희가 내린 결론입니다 ,,!! 백엔드 측 얘기는 안들어봐서 정확하지는 않은 정보인 거 같습니다.

};
```
그런데, 백엔드 서버측에서 proxy-middleware까지 요구하지 않는 경우, setupProxy.js 파일로 인해 500오류가 계속 발생할 수 있습니다.
![](https://velog.velcdn.com/images/gueit214/post/af36ebf8-c0c5-4066-8ba8-e500b03818f8/image.png)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 velog 이미지를 그대로 사용할 수 있군요 ㅋㅋ

- 파일, 제목, 내용을 DB에 저장하는 페이지가 있을 때
-> 파일을 http 통신으로 전송할 때 사용
>
**값은 무조건 "문자열"로 자동 변환** 되기에 객체나 배열 같은 복잡한 데이터 넣을 수 없습니다. 객체같은 경우, 아래의 코드처럼 for문을 돌려 key와 value를 분리한 후 넣어주면 됩니다.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json 문자열을 넣어서 사용하는 측에서 json 객체로 변환 처리하는 경우도 있더라구요 ㅋㅋ

headers: {
'Content-Type': 'multipart/form-data',
},
data: formData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오.. formdata 부분은 axios#post의 두번째 인자로 전달해야하는 걸로 알고 있었는데 위와 같이 해도 되는건가보네요.. config의 data는 request body로 전달하는 걸로 알고 있는데 문제 없이 동작할까요??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그런가요 ?? 저희는 문제없이 동작했습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

별 문제 없었나보군요.. 저도 가물가물해서 한번 실험해봐야겠네요 ㅋㅋ

@github-actions github-actions bot merged commit 17f4814 into master Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7주차 9기 프론트 블로그포스팅-프론트
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants