Class MultipartData

java.lang.Object
build.serve.form.MultipartData

public final class MultipartData extends Object
Parsed multipart/form-data request body.

Obtain an instance from an inbound Request:

var multipart = MultipartData.from(exchange.request());
var file = multipart.get("avatar");
var text = multipart.get("description").map(FormPart::value).orElse("");
Since:
Apr-2026
Author:
reed.vonredwitz
  • Method Details

    • from

      public static MultipartData from(build.serve.foundation.Request request)
      Parses multipart form data from the given Request.

      Reads the Content-Type header to extract the boundary.

      Parameters:
      request - the inbound request
      Returns:
      the parsed MultipartData
      Throws:
      IllegalArgumentException - if the Content-Type header is missing or has no boundary
    • parse

      public static MultipartData parse(byte[] body, String boundary)
      Parses multipart form data from raw bytes with the given boundary.
      Parameters:
      body - the raw multipart body
      boundary - the multipart boundary string
      Returns:
      the parsed MultipartData
    • get

      public Optional<FormPart> get(String name)
      Returns the first part with the given name, or empty if absent.
      Parameters:
      name - the field name
      Returns:
      the first matching FormPart, or empty
    • getAll

      public List<FormPart> getAll(String name)
      Returns all parts with the given name.
      Parameters:
      name - the field name
      Returns:
      all matching parts
    • parts

      public List<FormPart> parts()
      Returns all parts in this multipart body.
      Returns:
      all FormParts