HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧚
[1기]최종 프로젝트 데브코스
/
📜
[팀13] 사각사각 ✏️
/
🔥
트러블슈팅
/
🔥
HttpMediaTypeNotSupportedException는 뭘까?
🔥

HttpMediaTypeNotSupportedException는 뭘까?

요청 데이터
header={ authorization=, content-length=135022, referer=http://localhost:3000/, accept-language=ko-KR,ko;q=0.9, en-US;q=0.8, en;q=0.7, o rigin=http://localhost:3000, host={ip}:8080, //ip는 지웠습니다. connection=keep-alive, content-type=multipart/form-data; boundary=----WebKitFormBoundaryXgDJxgrLc2ZG8t6b, accept-encoding=gzip, deflate, accept=application/json, text/plain, */*, user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 }
 
error log
[2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout]2021-12-04 17:52:33.252 ERROR 16536 --- [http-nio-8080-exec-1] c.p.m.c.e.GlobalExceptionHandler : handleException [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout] [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout]org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/octet-stream' not supported [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout] at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:206) [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout] at org.springframework.web.servlet.mvc.method.annotation.RequestPartMethodArgumentResolver.resolveArgument(RequestPartMethodArgumentResolver.java:138) [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout] at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) [2021-12-04 17:52:33.253] [d-PLEKRAUQD][stdout] at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179)
 
client code
const response = await axios({ method: 'post', url: `http://ip/series/users/4`, headers: { Authorization: '', 'Content-Type': 'multipart/form-data', }, data: formData, }); const formData = new FormData(); formData.append('thumbnail', file); formData.append('request', JSON.stringify(request));
 
server code ver1
@PostMapping("/users/{userId}") @Operation(summary = "시리즈 공고 게시글 작성") @Tag(name = "[화면]-시리즈") public ApiResponse<SeriesSubscribePost.Response> postSeries( @PathVariable Long userId, @RequestPart MultipartFile thumbnail, @Valid @RequestPart SeriesSubscribePost.Request request) throws IOException { return ApiResponse.ok(HttpMethod.POST, seriesService.createSeries(userId, thumbnail, request)); }
 
server code ver2
@PostMapping(path = "/users/{userId}", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE }) @Operation(summary = "시리즈 공고 게시글 작성") @Tag(name = "[화면]-시리즈") public ApiResponse<SeriesSubscribePost.Response> postSeries( @PathVariable Long userId, @ModelAttribute SeriesSubscribePost.Thumbnail thumbnail, @Valid @RequestPart SeriesSubscribePost.Request request) throws IOException { return ApiResponse.ok( HttpMethod.POST, seriesService.createSeries(userId, thumbnail.thumbnail(), request)); }
 
참고 자료
https://www.baeldung.com/sprint-boot-multipart-requests
https://stackoverflow.com/questions/66971829/send-json-data-as-multipart-form-data-using-axios-post-request
http://daplus.net/java-postman에서-파일-및-json-데이터를-업로드하는-방법은-무엇/ https://www.baeldung.com/sprint-boot-multipart-requests
 

원인 : 클라이언트에서 blob 형식으로 데이터를 보내야함.