Springboot: Content-Type 'multipart/form-data' is not supported

2023. 9. 11. 14:27·🪲 bugs

발생 상황

  • multipart/formdata 콘텐트 타입으로 이미지를 요청 body에 받을 때 문제
org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'multipart/form-data;boundary=----WebKitFormBoundaryAwYdPgnCGZSXBO1H;charset=UTF-8' is not supported
    at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:209) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:163) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:136) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-6.0.11.jar:6.0.11]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-6.0.11.jar:6.0.11]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:118) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:884) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1081) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:974) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1011) ~[spring-webmvc-6.0.11.jar:6.0.11]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) ~[spring-webmvc-6.0.11.jar:6.0.11]

문제 파악

  • @RequestBody 어노테이션을 그래도 놔두었기 때문에 문제가 되었던 사례입니다.
  • Controller 에서 데이터를 받는 DTO 안에 MultipartFile을 추가하면서 수정해줘야하는 내용이 더 있는데 이부분을 저번에도 오류를 겪었으면서 오류를 반복했습니다 🥹
  • @ModelAttibute로 어노테이션을 수정했고 (생략해도 문제 없는 것 같습니다.) 다음과 같이 코드를 수정했습니다.
    @PostMapping(value = "/join", consumes = {"multipart/form-data"})
    @ResponseStatus(HttpStatus.CREATED)
    public BaseResponse<Join.Response> signup(@Valid @ModelAttribute Join.Request request) throws MemberException, IOException { //TODO 핸드폰번호 인증 후 session 조회 추가
        Join.Response result = memberFacade.joinNewMember(request);
        return BaseResponse.send("회원가입에 성공하였습니다.", result);
    }

Refs.

  • https://www.baeldung.com/sprint-boot-multipart-requests
저작자표시 비영리 동일조건 (새창열림)
'🪲 bugs' 카테고리의 다른 글
  • `@Cachable` 사용시 SpelEvaluationException 발생
  • Spring data JPA: Hibernate가 Sequence를 못찾아요
  • SpringSecurity: SecurityFilterChain 설정
  • Error: Cannot invoke because "this.repository" is null
iirin
iirin
별건 없고요, 조금씩 했던 것을 쌓아가고 있습니다. 이 블로그는 호기심과 재미로 추동됩니다 🚀
  • iirin
    ✨ iirin's space
    iirin
  • 전체
    오늘
    어제
    • ALL
      • 👩🏻‍💻 Computer Science
      • 💻 Operating System
      • ⚡️ Network
      • ☁️ Infra
      • 🥞 Database
      • 👽 Languages
        • ☕️ Java
        • ✔ Kotlin
      • ⚙️ Frameworks
        • 🌱 Spring
      • 🧩 Algorithm
      • 🪲 bugs
      • 💪 Practice
      • 💬 Smalltalk
      • 🔧 Tools
  • 블로그 메뉴

    • 링크

      • github
      • github page
    • 공지사항

    • 인기 글

    • 태그

      참조투명성
      test_container
      진법연산
      cs
      주간회고
      SpringBoot
      secondhand
      JPA
      mysql
      원격SSH
      BUG
      spring
      redis
      알고리즘
      Algorithm
      주소바인딩
      Java
      log
      test
      cache
      회고
      Error
      leetcode
      OS
      진법
      Kotlin
      coroutine
      top-interview-150
      논리적주소
      운영체제
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    iirin
    Springboot: Content-Type 'multipart/form-data' is not supported
    상단으로

    티스토리툴바