{"record":{"id":"0616951ee971fb89","repo":"quarkusio/quarkus","slug":"found-more-than-one-files-for-attribute-formn","errorCode":null,"errorMessage":"Found more than one files for attribute '\" + formName + \"'. Expected only one file","messagePattern":"Found more than one files for attribute '\" \\+ formName \\+ \"'\\. Expected only one file","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartSupport.java","lineNumber":328,"sourceCode":"        List<InputStream> ret = new ArrayList<InputStream>();\n        for (FormValue value : values) {\n            if (value.isFileItem()) {\n                try {\n                    ret.add(value.getFileItem().getInputStream());\n                } catch (IOException e) {\n                    throw new MultipartPartReadingException(e);\n                }\n            } else {\n                ret.add(new ByteArrayInputStream(value.getValue().getBytes(Charset.defaultCharset())));\n            }\n        }\n        return ret;\n    }\n\n    public static DefaultFileUpload getSingleFileUpload(String formName, ResteasyReactiveRequestContext context) {\n        List<DefaultFileUpload> uploads = getFileUploads(formName, context);\n        if (uploads.size() > 1) {\n            throw new BadRequestException(\"Found more than one files for attribute '\" + formName + \"'. Expected only one file\");\n        } else if (uploads.size() == 1) {\n            return uploads.get(0);\n        }\n        return null;\n    }\n\n    public static DefaultFileUpload getFileUpload(String formName, ResteasyReactiveRequestContext context) {\n        List<DefaultFileUpload> uploads = getFileUploads(formName, context);\n        if (!uploads.isEmpty()) {\n            return uploads.get(0);\n        }\n        return null;\n    }\n\n    public static List<DefaultFileUpload> getFileUploads(String formName, ResteasyReactiveRequestContext context) {\n        List<DefaultFileUpload> result = new ArrayList<>();\n        FormData formData = context.getFormData();\n        if (formData != null) {","sourceCodeStart":310,"sourceCodeEnd":346,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartSupport.java#L310-L346","documentation":"MultipartSupport.getSingleFileUpload throws a BadRequestException when a form attribute expected to contain exactly one file upload contains more than one. It is used to bind a single-file endpoint parameter but the client sent multiple parts with the same name. The request is rejected with 400.","triggerScenarios":"A client uploads two or more file parts under the same form field name while the endpoint declares a single FileUpload/Path parameter for that name.","commonSituations":"HTML file input allowing multiple selection against a single-file endpoint; client retry appending a duplicate part; API consumers batching files under one attribute name.","solutions":["Inject a List<FileUpload> (or array) instead of a single FileUpload and validate/iterate yourself.","Fix the client to send only one part per attribute (remove the multiple attribute from the input).","Validate the count client-side before submitting and surface a clear error to the user.","If duplicates are accidental from client retries, deduplicate on the client before sending."],"exampleFix":"// before\n@RestForm(\"attachment\") FileUpload attachment; // 400 if 2 files sent\n// after\n@RestForm(\"attachment\") List<FileUpload> attachments;\nif (attachments.size() != 1) { throw new BadRequestException(\"exactly one attachment required\"); }","handlingStrategy":"validation","validationCode":"List<FileUpload> uploads = getFileUploads(\"attachment\", context); if (uploads.size() > 1) { throw new BadRequestException(\"send at most one 'attachment' file\"); }","typeGuard":null,"tryCatchPattern":"try { FileUpload f = getSingleFileUpload(\"attachment\", context); } catch (BadRequestException e) { return Response.status(400).entity(\"Only one file allowed\").build(); }","preventionTips":["Remove the `multiple` attribute from single-file inputs","Use List<FileUpload> when multiple files are legitimate","Validate file count client-side before submit","Document the one-file contract for API consumers"],"tags":["multipart","file-upload","bad-request"],"backgroundTag":"multiple-file-parts-for-single-attribute","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}