quarkusio/quarkus · error · BadRequestException

Found more than one files for attribute '" + formName + "'.

Error message

Found more than one files for attribute '" + formName + "'. Expected only one file

What it means

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.

Source

Thrown at independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/multipart/MultipartSupport.java:328

        List<InputStream> ret = new ArrayList<InputStream>();
        for (FormValue value : values) {
            if (value.isFileItem()) {
                try {
                    ret.add(value.getFileItem().getInputStream());
                } catch (IOException e) {
                    throw new MultipartPartReadingException(e);
                }
            } else {
                ret.add(new ByteArrayInputStream(value.getValue().getBytes(Charset.defaultCharset())));
            }
        }
        return ret;
    }

    public static DefaultFileUpload getSingleFileUpload(String formName, ResteasyReactiveRequestContext context) {
        List<DefaultFileUpload> uploads = getFileUploads(formName, context);
        if (uploads.size() > 1) {
            throw new BadRequestException("Found more than one files for attribute '" + formName + "'. Expected only one file");
        } else if (uploads.size() == 1) {
            return uploads.get(0);
        }
        return null;
    }

    public static DefaultFileUpload getFileUpload(String formName, ResteasyReactiveRequestContext context) {
        List<DefaultFileUpload> uploads = getFileUploads(formName, context);
        if (!uploads.isEmpty()) {
            return uploads.get(0);
        }
        return null;
    }

    public static List<DefaultFileUpload> getFileUploads(String formName, ResteasyReactiveRequestContext context) {
        List<DefaultFileUpload> result = new ArrayList<>();
        FormData formData = context.getFormData();
        if (formData != null) {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Inject a List<FileUpload> (or array) instead of a single FileUpload and validate/iterate yourself.
  2. Fix the client to send only one part per attribute (remove the multiple attribute from the input).
  3. Validate the count client-side before submitting and surface a clear error to the user.
  4. If duplicates are accidental from client retries, deduplicate on the client before sending.

Example fix

// before
@RestForm("attachment") FileUpload attachment; // 400 if 2 files sent
// after
@RestForm("attachment") List<FileUpload> attachments;
if (attachments.size() != 1) { throw new BadRequestException("exactly one attachment required"); }
Defensive patterns

Strategy: validation

Validate before calling

List<FileUpload> uploads = getFileUploads("attachment", context); if (uploads.size() > 1) { throw new BadRequestException("send at most one 'attachment' file"); }

Try / catch

try { FileUpload f = getSingleFileUpload("attachment", context); } catch (BadRequestException e) { return Response.status(400).entity("Only one file allowed").build(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/0616951ee971fb89. Report an issue: GitHub.