MultipartFormData¶
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()
Constructors¶
create¶
Create a new builder with a randomly generated boundary string.
Returns¶
- MultipartFormData ref^
Public Functions¶
field¶
Add a text field to the form.
" and \ in the name are automatically backslash-escaped in the
serialized Content-Disposition quoted-string.
Parameters¶
Returns¶
file¶
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¶
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.
Returns¶
- String val
body¶
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.