OpenFeign/feign · error · UnsupportedOperationException

SpringManyMultipartFilesReader does not support writing to…

Error message

SpringManyMultipartFilesReader does not support writing to HTTP body.

What it means

SpringManyMultipartFilesReader is a read-only HttpMessageConverter: it converts incoming multipart bodies into MultipartFile arrays but cannot serialize MultipartFile arrays back to an HTTP body. writeInternal is deliberately unimplemented and always throws UnsupportedOperationException.

Solutions

  1. Do not use this converter to write; register a multipart-capable encoder (e.g. SpringFormEncoder from feign-form-spring) for encoding MultipartFile bodies
  2. Return the file bytes/Resource or a ResponseEntity<Resource> from controllers instead of MultipartFile[]
  3. Ensure the Feign client is configured with the form encoder so multipart writes never reach this converter

Example fix

// before
Feign.builder().encoder(new Default()).target(Portal.class, url);
// after
Feign.builder().encoder(new SpringFormEncoder()).target(Portal.class, url);
Defensive patterns

Strategy: validation

Validate before calling

// never route MultipartFile[] through a read-only converter
if (output instanceof MultipartFile[]) {
  throw new IllegalStateException("use a multipart encoder (SpringFormEncoder) for writing");
}

Prevention

When it happens

Trigger: Passing a MultipartFile[] (or MultipartFile) as a return value of a controller, or as a request body to an outbound call routed through this converter instead of a proper multipart encoder.

Common situations: Trying to return MultipartFile[] from a Spring @RequestMapping handler, or misconfiguring a Feign client so a MultipartFile[] body is handed to the reader-converter instead of feign-form's SpringFormEncoder.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/d42fe50f4df33615. Report an issue: GitHub.

Appendix: source

Thrown at form-spring/src/main/java/feign/form/spring/converter/SpringManyMultipartFilesReader.java:120

    for (boolean nextPart = multipartStream.skipPreamble();
        nextPart;
        nextPart = multipartStream.readBoundary()) {
      ByteArrayMultipartFile multiPart;
      try {
        multiPart = readMultiPart(multipartStream);
      } catch (Exception e) {
        throw new HttpMessageNotReadableException(
            "Multipart body could not be read.", e, inputMessage);
      }
      multiparts.add(multiPart);
    }
    return multiparts.toArray(new ByteArrayMultipartFile[0]);
  }

  @Override
  protected void writeInternal(
      MultipartFile[] byteArrayMultipartFiles, HttpOutputMessage outputMessage) {
    throw new UnsupportedOperationException(
        getClass().getSimpleName() + " does not support writing to HTTP body.");
  }

  private byte[] getMultiPartBoundary(MediaType contentType) {
    val boundaryString = unquote(contentType.getParameter("boundary"));
    if (StringUtils.hasLength(boundaryString) == false) {
      throw new HttpMessageConversionException("Content-Type missing boundary information.");
    }
    return boundaryString.getBytes(UTF_8);
  }

  private ByteArrayMultipartFile readMultiPart(MultipartStream multipartStream) throws IOException {
    val multiPartHeaders =
        splitIntoKeyValuePairs(
            multipartStream.readHeaders(), NEWLINES_PATTERN, COLON_PATTERN, false);

    val contentDisposition =
        splitIntoKeyValuePairs(

View on GitHub (pinned to e2a1e27560)