Skip to content

MultipartFormData

[Source]

Build a multipart/form-data body for file uploads and mixed form submissions (RFC 7578).

Use field() for plain text values and file() for file attachments. After adding all parts, pass the builder to multipart_body() on the request builder, which sets both the body and Content-Type header.

For simple key-value form data without files, use FormEncoder with form_body() instead — it produces the more compact application/x-www-form-urlencoded format.

let form = MultipartFormData
  .> field("username", "alice")
  .> file("avatar", "photo.jpg", "image/jpeg", image_data)
let req = Request.post("/upload")
  .multipart_body(form)
  .build()
class ref MultipartFormData

Constructors

create

[Source]

Create a new builder with a randomly generated boundary string.

new ref create()
: MultipartFormData ref^

Returns


Public Functions

field

[Source]

Add a text field to the form.

" and \ in the name are automatically backslash-escaped in the serialized Content-Disposition quoted-string.

fun ref field(
  name: String val,
  value: String val)
: MultipartFormData ref

Parameters

Returns


file

[Source]

Add a file attachment to the form.

" and \ in the name and filename are automatically backslash-escaped in the serialized Content-Disposition quoted-string.

fun ref file(
  name: String val,
  filename: String val,
  file_content_type: String val,
  data: Array[U8 val] val)
: MultipartFormData ref

Parameters

Returns


content_type

[Source]

Return the Content-Type header value including the boundary parameter.

Pass this to the request's Content-Type header so the server knows how to parse the body. The multipart_body() method on the request builder does this automatically.

fun box content_type()
: String val

Returns


body

[Source]

Serialize all parts into the multipart/form-data wire format.

Each part is delimited by the boundary string. Field parts include a Content-Disposition header; file parts additionally include a filename parameter and a Content-Type header. The body ends with a closing boundary.

Field names and filenames are backslash-escaped (" becomes \", \ becomes \\) within Content-Disposition quoted-strings.

fun box body()
: Array[U8 val] val

Returns