{"record":{"id":"d42fe50f4df33615","repo":"OpenFeign/feign","slug":"springmanymultipartfilesreader-does-not-support-wr","errorCode":null,"errorMessage":"SpringManyMultipartFilesReader does not support writing to HTTP body.","messagePattern":"SpringManyMultipartFilesReader does not support writing to HTTP body\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"form-spring/src/main/java/feign/form/spring/converter/SpringManyMultipartFilesReader.java","lineNumber":120,"sourceCode":"    for (boolean nextPart = multipartStream.skipPreamble();\n        nextPart;\n        nextPart = multipartStream.readBoundary()) {\n      ByteArrayMultipartFile multiPart;\n      try {\n        multiPart = readMultiPart(multipartStream);\n      } catch (Exception e) {\n        throw new HttpMessageNotReadableException(\n            \"Multipart body could not be read.\", e, inputMessage);\n      }\n      multiparts.add(multiPart);\n    }\n    return multiparts.toArray(new ByteArrayMultipartFile[0]);\n  }\n\n  @Override\n  protected void writeInternal(\n      MultipartFile[] byteArrayMultipartFiles, HttpOutputMessage outputMessage) {\n    throw new UnsupportedOperationException(\n        getClass().getSimpleName() + \" does not support writing to HTTP body.\");\n  }\n\n  private byte[] getMultiPartBoundary(MediaType contentType) {\n    val boundaryString = unquote(contentType.getParameter(\"boundary\"));\n    if (StringUtils.hasLength(boundaryString) == false) {\n      throw new HttpMessageConversionException(\"Content-Type missing boundary information.\");\n    }\n    return boundaryString.getBytes(UTF_8);\n  }\n\n  private ByteArrayMultipartFile readMultiPart(MultipartStream multipartStream) throws IOException {\n    val multiPartHeaders =\n        splitIntoKeyValuePairs(\n            multipartStream.readHeaders(), NEWLINES_PATTERN, COLON_PATTERN, false);\n\n    val contentDisposition =\n        splitIntoKeyValuePairs(","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/form-spring/src/main/java/feign/form/spring/converter/SpringManyMultipartFilesReader.java#L102-L138","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Do not use this converter to write; register a multipart-capable encoder (e.g. SpringFormEncoder from feign-form-spring) for encoding MultipartFile bodies","Return the file bytes/Resource or a ResponseEntity<Resource> from controllers instead of MultipartFile[]","Ensure the Feign client is configured with the form encoder so multipart writes never reach this converter"],"exampleFix":"// before\nFeign.builder().encoder(new Default()).target(Portal.class, url);\n// after\nFeign.builder().encoder(new SpringFormEncoder()).target(Portal.class, url);","handlingStrategy":"validation","validationCode":"// never route MultipartFile[] through a read-only converter\nif (output instanceof MultipartFile[]) {\n  throw new IllegalStateException(\"use a multipart encoder (SpringFormEncoder) for writing\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Register SpringFormEncoder as the Feign encoder when bodies may be files","Never return MultipartFile[] from controllers; return byte[] or Resource instead","Review converter registrations to keep readers and writers separate"],"tags":["spring","multipart","unsupported-operation","encoder"],"backgroundTag":"unsupported-operation","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}