OpenFeign/feign · error · HttpMessageConversionException

Content-Disposition is not of type form-data.

Error message

Content-Disposition is not of type form-data.

What it means

Each part of a multipart/form-data body must carry Content-Disposition: form-data with name/filename parameters. If a part's Content-Disposition header cannot be parsed into something containing the form-data token, the reader rejects the part.

Solutions

  1. Fix the client's multipart encoder to emit 'Content-Disposition: form-data; name="..."; filename="..."' per part
  2. If using feign-form, upgrade — it emits correct headers; verify the boundary matches the body so headers parse at correct offsets
  3. Inspect raw bytes of the part headers to confirm they are not offset by a boundary mismatch

Example fix

// before (hand-built part)
output.write(("Content-Disposition: attachment; name=\"file\"\r\n").getBytes());
// after
output.write(("Content-Disposition: form-data; name=\"file\"; filename=\"a.txt\"\r\n").getBytes());
Defensive patterns

Strategy: validation

Validate before calling

// verify each part header on the sending side
// Content-Disposition: form-data; name="file"; filename="x.txt"
assert disposition.startsWith("form-data") : "part must be form-data";

Try / catch

try {
  return readMultiPart(stream);
} catch (HttpMessageConversionException e) {
  throw new BadRequestException("malformed part: " + e.getMessage());
}

Prevention

When it happens

Trigger: readMultiPart encounters a part whose Content-Disposition header is missing, malformed, or declares another disposition type (e.g. attachment) — typically because the client generated the multipart body incorrectly.

Common situations: Hand-rolled multipart encoders writing wrong headers, proxies re-formatting headers, or body bytes misaligned so header parsing picks up garbage (often a symptom of a boundary mismatch).

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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

Appendix: source

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

      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(
            multiPartHeaders.get(CONTENT_DISPOSITION),
            SEMICOLON_PATTERN,
            EQUALITY_SIGN_PATTERN,
            true);

    if (!contentDisposition.containsKey("form-data")) {
      throw new HttpMessageConversionException("Content-Disposition is not of type form-data.");
    }

    val bodyStream = new ByteArrayOutputStream();
    multipartStream.readBodyData(bodyStream);
    return new ByteArrayMultipartFile(
        contentDisposition.get("name"),
        contentDisposition.get("filename"),
        multiPartHeaders.get(CONTENT_TYPE),
        bodyStream.toByteArray());
  }

  private Map<String, String> splitIntoKeyValuePairs(
      String str,
      Pattern entriesSeparatorPattern,
      Pattern keyValueSeparatorPattern,
      boolean unquoteValue) {
    val keyValuePairs = new IgnoreKeyCaseMap();
    if (StringUtils.hasLength(str)) {

View on GitHub (pinned to e2a1e27560)