{"record":{"id":"9b2d79294d5df2e8","repo":"flowable/flowable-engine","slug":"cannot-create-multi-part-entity","errorCode":null,"errorMessage":"Cannot create multi part entity","messagePattern":"Cannot create multi part entity","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-http-common/src/main/java/org/flowable/http/common/impl/apache/client5/ApacheHttpComponents5FlowableHttpClient.java","lineNumber":281,"sourceCode":"                        entityBuilder.addBinaryBody(name, (byte[]) value, ContentType.DEFAULT_BINARY, part.getFilename());\n                    }\n                } else if (value instanceof String) {\n                    if (StringUtils.isNotBlank(part.getMimeType())) {\n                        entityBuilder.addTextBody(name, (String) value, ContentType.create(part.getMimeType()));\n                    } else {\n                        entityBuilder.addTextBody(name, (String) value);\n                    }\n                } else if (value != null) {\n                    throw new FlowableIllegalArgumentException(\"Value of type \" + value.getClass() + \" is not supported as multi part content\");\n                }\n            }\n\n            try (HttpEntity multiPartEntity = entityBuilder.build();\n                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream((int) multiPartEntity.getContentLength())) {\n                multiPartEntity.writeTo(outputStream);\n                requestBase.setEntity(outputStream.toByteArray(), ContentType.parse(multiPartEntity.getContentType()));\n            } catch (IOException e) {\n                throw new FlowableException(\"Cannot create multi part entity\", e);\n            }\n        } else if (requestInfo.getFormParameters() != null) {\n            Map<String, List<String>> formParameters = requestInfo.getFormParameters();\n            List<BasicNameValuePair> parameters = new ArrayList<>(formParameters.size());\n            for (Map.Entry<String, List<String>> entry : formParameters.entrySet()) {\n                String name = entry.getKey();\n                for (String value : entry.getValue()) {\n                    parameters.add(new BasicNameValuePair(name, value));\n                }\n            }\n\n            Charset charset = requestInfo.getBodyEncoding() != null ? Charset.forName(requestInfo.getBodyEncoding()) : null;\n\n            String formParametersString = WWWFormCodec.format(parameters, charset);\n            requestBase.setEntity(AsyncEntityProducers.create(formParametersString, ContentType.APPLICATION_FORM_URLENCODED.withCharset(charset)));\n        }\n    }\n","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/impl/apache/client5/ApacheHttpComponents5FlowableHttpClient.java#L263-L299","documentation":"After assembling the multipart entity, the HttpClient 5.x client serializes it: `multiPartEntity.writeTo(outputStream)` writes the fully formed multipart body into a `ByteArrayOutputStream`. An `IOException` during this in-memory serialization is wrapped as `FlowableException(\"Cannot create multi part entity\", e)`.","triggerScenarios":"`setRequestEntity()` fails when `multiPartEntity.writeTo(outputStream)` or `multiPartEntity.getContentLength()` throws — typically because a part's backing content stream fails while being read/written.","commonSituations":"Part content backed by a closed or broken stream; content length overflow (entity larger than `Integer.MAX_VALUE` used for the ByteArrayOutputStream initial size); charset/encoding issues on part content.","solutions":["Inspect the chained cause for the underlying stream failure and fix the part data source.","Ensure part values are fully materialized, stable `String`/`byte[]` values (not live streams).","Reduce multipart payload size — the entire entity is buffered in memory before the request is sent.","Upgrade/verify httpmime and httpclient5 versions if the entity's writeTo fails due to a library bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// keep total multipart payload well under Integer.MAX_VALUE since it is buffered in memory\nlong estimated = parts.values().stream().mapToLong(v -> v instanceof byte[] b ? b.length : String.valueOf(v).length()).sum();\nif (estimated > 64 * 1024 * 1024) {\n    throw new IllegalStateException(\"Multipart payload too large for in-memory serialization: \" + estimated + \" bytes\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return client.call(requestInfo);\n} catch (FlowableException e) {\n    if (\"Cannot create multi part entity\".equals(e.getMessage()) && e.getCause() != null) {\n        log.error(\"Multipart serialization failed: {}\", e.getCause().getMessage(), e.getCause());\n    }\n    throw e;\n}","preventionTips":["Use fully materialized String/byte[] part values, not live streams.","Cap multipart body sizes; the entity is buffered in a byte array.","Fix or replace failing data sources before building the request."],"tags":["multipart","io","http-client","serialization"],"backgroundTag":"http-request-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}