object

# `http_multipart`

Multipart helper predicates built on top of the normalized body and part terms provided by the http library.

Availability:
`logtalk_load(http_multipart(loader))`
Author: Paulo Moura
Version: 1:0:0
Date: 2026-06-26
Compilation flags:
`static, context_switching_calls`
Imports:
`public` http_text_helpers
Uses:
http_core
list
type
Remarks:
(none)
Inherited public predicates:
(none)

## Public predicates

### `body/3`

Constructs a validated normalized multipart body term from a multipart media type atom and a list of multipart parts.

Compilation flags:
`static`
Template:
`body(MediaType,Parts,Body)`
Mode and number of proofs:
`body(+atom,+list(compound),-compound)` - `one_or_error`
Exceptions:
`MediaType` is not a valid multipart media type atom:
`domain_error(http_multipart_media_type,MediaType)`
`Parts` is not a valid list of normalized multipart parts:
`domain_error(http_multipart_parts,Parts)`

### `is_body/1`

True when the argument is a valid normalized multipart body term.

Compilation flags:
`static`
Template:
`is_body(Body)`
Mode and number of proofs:
`is_body(@term)` - `zero_or_one`

### `parse/4`

Parses a multipart body from a source term by delegating to the underlying `http_core::parse_body/4` predicate after validating the media type.

Compilation flags:
`static`
Template:
`parse(Source,MediaType,Options,Body)`
Mode and number of proofs:
`parse(++compound,+atom,+list,-compound)` - `one_or_error`
Exceptions:
`MediaType` is not a valid multipart media type atom:
`domain_error(http_multipart_media_type,MediaType)`
`Source` is a variable:
`instantiation_error`
`Source` is neither a variable nor a valid HTTP source term:
`domain_error(http_source,Source)`
`Options` is not a valid HTTP body options list:
`domain_error(http_body_options,Options)`
No registered HTTP body codec exists for `MediaType` when codec-based decoding is required:
`existence_error(http_body_codec,MediaType)`
The parsed body is not a valid normalized multipart body term:
`domain_error(http_multipart_body,Body)`

### `generate/3`

Generates a multipart body to a sink term by delegating to the underlying `http_core::generate_body/3` predicate after validating the multipart body term.

Compilation flags:
`static`
Template:
`generate(Sink,Body,Options)`
Mode and number of proofs:
`generate(++compound,+compound,+list)` - `one_or_error`
Exceptions:
`Body` is not a valid normalized multipart body term:
`domain_error(http_multipart_body,Body)`
`Sink` is a variable:
`instantiation_error`
`Sink` is neither a variable nor a valid HTTP sink term:
`domain_error(http_sink,Sink)`
`Options` is not a valid HTTP body options list:
`domain_error(http_body_options,Options)`
No registered HTTP body codec exists for the body media type when codec-based encoding is required:
`existence_error(http_body_codec,MediaType)`

### `media_type/2`

Returns the media type atom of a validated multipart body term.

Compilation flags:
`static`
Template:
`media_type(Body,MediaType)`
Mode and number of proofs:
`media_type(+compound,-atom)` - `one_or_error`
Exceptions:
`Body` is not a valid normalized multipart body term:
`domain_error(http_multipart_body,Body)`

### `parts/2`

Returns the list of multipart part terms of a validated multipart body term.

Compilation flags:
`static`
Template:
`parts(Body,Parts)`
Mode and number of proofs:
`parts(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Body` is not a valid normalized multipart body term:
`domain_error(http_multipart_body,Body)`

### `fields/2`

Returns the list of form-data field(Name, Value, Parameters) descriptors found in a validated multipart/form-data body, preserving part order.

Compilation flags:
`static`
Template:
`fields(Body,Fields)`
Mode and number of proofs:
`fields(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Body` is not a valid normalized multipart/form-data body term:
`domain_error(http_multipart_form_data_body,Body)`

### `files/2`

Returns the list of form-data `file(Name, Filename, MediaType, Payload, Parameters)` descriptors found in a validated multipart/form-data body, preserving part order.

Compilation flags:
`static`
Template:
`files(Body,Files)`
Mode and number of proofs:
`files(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Body` is not a valid normalized multipart/form-data body term:
`domain_error(http_multipart_form_data_body,Body)`

### `part/4`

Constructs a validated normalized multipart part term from headers, body, and properties.

Compilation flags:
`static`
Template:
`part(Headers,Body,Properties,Part)`
Mode and number of proofs:
`part(+list(compound),+compound,+list(compound),-compound)` - `one_or_error`
Exceptions:
The given headers, body, and properties do not form a valid normalized multipart part term:
`domain_error(http_multipart_part,Part)`

### `is_part/1`

True when the argument is a valid normalized multipart part term.

Compilation flags:
`static`
Template:
`is_part(Part)`
Mode and number of proofs:
`is_part(@term)` - `zero_or_one`

### `part_headers/2`

Returns the headers of a validated multipart part term.

Compilation flags:
`static`
Template:
`part_headers(Part,Headers)`
Mode and number of proofs:
`part_headers(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Part` is not a valid normalized multipart part term:
`domain_error(http_multipart_part,Part)`

### `part_body/2`

Returns the body of a validated multipart part term.

Compilation flags:
`static`
Template:
`part_body(Part,Body)`
Mode and number of proofs:
`part_body(+compound,-compound)` - `one_or_error`
Exceptions:
`Part` is not a valid normalized multipart part term:
`domain_error(http_multipart_part,Part)`

### `part_properties/2`

Returns the properties of a validated multipart part term.

Compilation flags:
`static`
Template:
`part_properties(Part,Properties)`
Mode and number of proofs:
`part_properties(+compound,-list(compound))` - `one_or_error`
Exceptions:
`Part` is not a valid normalized multipart part term:
`domain_error(http_multipart_part,Part)`

### `field/4`

True when the validated multipart part is a textual form-data field part, returning its field name, text value, and additional disposition parameters.

Compilation flags:
`static`
Template:
`field(Part,Name,Value,Parameters)`
Mode and number of proofs:
`field(+compound,-atom,-term,-list(compound))` - `zero_or_one`

### `file/6`

True when the validated multipart part is a form-data file part, returning its field name, filename, media type, payload term, and additional disposition parameters.

Compilation flags:
`static`
Template:
`file(Part,Name,Filename,MediaType,Payload,Parameters)`
Mode and number of proofs:
`file(+compound,-atom,-atom,-atom,-compound,-list(compound))` - `zero_or_one`

### `field_part/4`

Constructs a normalized multipart part for a textual form-data field using a content-disposition header, a text/plain body, and additional disposition parameters.

Compilation flags:
`static`
Template:
`field_part(Name,Value,Parameters,Part)`
Mode and number of proofs:
`field_part(+atom,+term,+list(compound),-compound)` - `one_or_error`
Exceptions:
`Name` is not a valid form-data field name:
`domain_error(http_multipart_form_data_parameter_name,Name)`
`Parameters` is not a valid list of additional form-data disposition parameters:
`domain_error(http_multipart_form_data_parameters,Parameters)`
A form-data disposition parameter is invalid for a textual field part:
`domain_error(http_multipart_form_data_parameter,Parameter)`

### `file_part/6`

Constructs a normalized multipart part for a form-data file using a content-disposition header, the given media type and payload, and additional disposition parameters.

Compilation flags:
`static`
Template:
`file_part(Name,Filename,MediaType,Payload,Parameters,Part)`
Mode and number of proofs:
`file_part(+atom,+atom,+atom,+compound,+list(compound),-compound)` - `one_or_error`
Exceptions:
`Name` is not a valid form-data field name:
`domain_error(http_multipart_form_data_parameter_name,Name)`
`Filename` is not a valid form-data filename value:
`domain_error(http_multipart_form_data_parameter_value,Filename)`
`Parameters` is not a valid list of additional form-data disposition parameters:
`domain_error(http_multipart_form_data_parameters,Parameters)`
A form-data disposition parameter is invalid for a file part:
`domain_error(http_multipart_form_data_parameter,Parameter)`

### `form_data_body/2`

Constructs a multipart/form-data body from an ordered list of `field(Name, Value, Parameters)` and `file(Name, Filename, MediaType, Payload, Parameters)` descriptors.

Compilation flags:
`static`
Template:
`form_data_body(Items,Body)`
Mode and number of proofs:
`form_data_body(+list(compound),-compound)` - `one_or_error`
Exceptions:
`Items` is not a valid list of form-data field or file descriptors:
`domain_error(http_multipart_form_data_items,Items)`

## Protected predicates

(no local declarations; see entity ancestors if any)

## Private predicates

(no local declarations; see entity ancestors if any)

## Operators

(none)