{"record":{"id":"a6c816b8cd3e4f09","repo":"testcontainers/testcontainers-java","slug":"unable-to-upload-binary-responsebody","errorCode":null,"errorMessage":"Unable to upload binary\n${responseBody}","messagePattern":"Unable to upload binary\n(.+?)","errorType":"exception","errorClass":"SolrClientUtilsException","httpStatus":null,"severity":"error","filePath":"modules/solr/src/main/java/org/testcontainers/containers/SolrClientUtils.java","lineNumber":91,"sourceCode":"        }\n        HttpUrl url = generateSolrURL(hostname, port, Arrays.asList(\"admin\", \"collections\"), parameters);\n        executePost(url, null);\n    }\n\n    private static void executePost(HttpUrl url, byte[] data) throws IOException {\n        RequestBody requestBody = data == null\n            ? RequestBody.create(MediaType.parse(\"text/plain\"), \"\")\n            : RequestBody.create(MediaType.parse(\"application/octet-stream\"), data);\n        Request request = new Request.Builder().url(url).post(requestBody).build();\n\n        Response response = httpClient.newCall(request).execute();\n        if (!response.isSuccessful()) {\n            String responseBody = \"\";\n            if (response.body() != null) {\n                responseBody = response.body().string();\n                response.close();\n            }\n            throw new SolrClientUtilsException(response.code(), \"Unable to upload binary\\n\" + responseBody);\n        }\n        if (response.body() != null) {\n            response.close();\n        }\n    }\n\n    private static HttpUrl generateSolrURL(\n        String hostname,\n        int port,\n        List<String> pathSegments,\n        Map<String, String> parameters\n    ) throws URISyntaxException {\n        HttpUrl.Builder builder = new HttpUrl.Builder();\n        builder.scheme(\"http\");\n        builder.host(hostname);\n        builder.port(port);\n        // Path\n        builder.addPathSegment(\"solr\");","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/solr/src/main/java/org/testcontainers/containers/SolrClientUtils.java#L73-L109","documentation":"SolrClientUtils.executePost performs an HTTP POST (file upload) to the running Solr container using OkHttp. When the response is not successful, it reads the body and throws SolrClientUtilsException with message 'Unable to upload binary' plus the response body. Called by uploadConfiguration and createCollection.","triggerScenarios":"uploadConfiguration() or createCollection() failing server-side: Solr API rejecting the config zip, bad collection name, ZooKeeper issues, or hitting the wrong port/path, producing a non-2xx response.","commonSituations":"Uploading a malformed/oversized configset zip, creating a collection that already exists, Solr not fully started yet, wrong Solr version API differences, network/DNS issues inside the container network.","solutions":["Read the responseBody appended to the exception message — it usually contains Solr's own error explaining the rejection.","Ensure the container is fully started before calling uploadConfiguration/createCollection (Testcontainers wait strategy should cover this; add wait checks if using manually).","Validate the configuration zip structure (solrconfig.xml, schema files at zip root or under conf/).","Check the collection name doesn't already exist or delete it first; use a unique name per test run.","Enable OkHttp/Solr request logging to inspect the exact request URL and payload if the body message is vague."],"exampleFix":"// before\ntry {\n    SolrClientUtils.uploadConfiguration(container, \"myconfig\", Paths.get(\"bad-config.zip\"));\n} catch (SolrClientUtilsException e) {\n    // ignore\n}\n// after\ntry {\n    SolrClientUtils.uploadConfiguration(container, \"myconfig\", Paths.get(\"conf.zip\"));\n} catch (SolrClientUtilsException e) {\n    LOGGER.error(\"Solr returned code {} body: {}\", e.getStatusCode(), e.getMessage(), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// before calling\nif (!container.isRunning()) throw new IllegalStateException(\"Solr container not started\");\nif (configZip == null || !Files.exists(configZip)) throw new IllegalStateException(\"Config zip missing: \" + configZip);","typeGuard":null,"tryCatchPattern":"try {\n  SolrClientUtils.uploadConfiguration(container, name, zipPath);\n  SolrClientUtils.createCollection(container, name);\n} catch (SolrClientUtilsException e) {\n  LOGGER.error(\"Solr utils failed with HTTP {}: {}\", e.getStatusCode(), e.getMessage(), e);\n  throw e;\n}","preventionTips":["Always log the response body embedded in SolrClientUtilsException","Wait for Solr readiness before uploads (Testcontainers wait strategy)","Validate configset zip layout and unique collection names per run"],"tags":["solr","http","upload","api-error"],"backgroundTag":"http-error-response","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}