코드스테이츠/메인프로젝트

Content type 'application/octet-stream' not supported

서하빈 2023. 5. 22. 17:50

@RequestPart 애너테이션을 이용하여 json과 이미지를 동시에 받는 서버 코드

 

form-data 형식으로 postman 테스트

- 위와 같은 상황에서 postman으로 테스트를 진행하면 문제없이 되는데 클라이언트에서 요청을 보내면 Content type 'application/octet-stream' not supported 에러가 발생함.

 

 

- 해결방법: formdata에 json을 그냥 넣지 않고 blob으로 감싼 후 type을 application/json으로 명시한 후에 넣는다.

 

 

문제 코드

fd.append("dto", JSON.stringify(inputs);

 

 

해결 코드

const json = JSON.stringify(inputs);
const blob = new Blob([json], { type: "application/json" });
fd.append("dto", blob);