Skip to content

Multipart

Encode multipart connector requests without JSON-encoding file content.

Classes

MultipartFile dataclass

MultipartFile(content: bytes, file_name: str = 'blob', content_type: str = 'application/octet-stream')

A buffered upload with a filename and media type.

Parameters:

Name Type Description Default
content bytes

The unencoded file bytes.

required
file_name str

The filename sent in the part's Content-Disposition header.

'blob'
content_type str

The file's media type.

'application/octet-stream'

Functions:

encode_multipart_form_data async

encode_multipart_form_data(fields: Iterable[tuple[str, str | bytes | MultipartFile]]) -> tuple[bytes, str]

Encode ordered fields, including repeated names and empty forms.

Parameters:

Name Type Description Default
fields Iterable[tuple[str, str | bytes | MultipartFile]]

Wire field names and text or binary values. Plain bytes use the default filename and media type from MultipartFile.

required

Returns:

Type Description
tuple[bytes, str]

The complete body bytes and their boundary-bearing content type.

Raises:

Type Description
TypeError

If a field is neither text nor a supported binary value.