multipart module

Build and parse multipart/form-data bodies. Mostly you'll use this through request.upload / web.parse_form, but the primitives are here when you need them.

import "multipart" as multipart;

var boundary = multipart.generate_boundary();
var body = multipart.encode([
    { name: "user", value: "alice" },
    { name: "avatar", filename: "a.png", content_type: "image/png", data: bytes }
], boundary);

API

FunctionDescription
multipart.generate_boundary() → stringA fresh random boundary token.
multipart.encode(parts, boundary) → stringSerialize a list of parts. Each part: {name, value} or {name, filename, content_type, data}.
multipart.decode(body, boundary) → listParse a complete body into a list of parts.
multipart.streaming_decode(boundary, on_part_start, on_part_chunk, on_part_end)Push-style parser for huge uploads — feed chunks as they arrive.

See also

  • requestreq.upload / req.upload_with use this.
  • web — incoming multipart is parsed into req.parts.