Documentation
¶
Overview ¶
Package formdata assembles a multipart/form-data request body from an object of form fields (#1296): the encoder the api gateway sends an operation that takes form data through, with the boundary generated here and authoritative over any Content-Type a caller supplied. It knows nothing about connections or operations, only the value-shape rules a body object follows.
Index ¶
Constants ¶
const MediaType = "multipart/form-data"
MediaType is the media type this encoder answers for. An operation whose catalog entry declares it (or a caller who pins it in headers) gets a body assembled by mime/multipart rather than json.Marshal (issue #1296).
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode assembles a multipart/form-data body from an object body and returns it with the Content-Type carrying the generated boundary.
The body must be a JSON object; each key is one form field:
- a scalar becomes a plain text field,
- an array becomes one part per element under the same field name,
- an object carrying any of filename / content / content_base64 / content_type becomes a part with those attributes: content is sent as UTF-8 text, content_base64 is decoded first, and a part naming a filename defaults to application/octet-stream. Such an object may carry no other key, so a typo is refused rather than dropped,
- any other object is JSON-encoded into a text field, which is how upstreams that take a JSON metadata field alongside a file part expect it.
The returned encoding is authoritative: the boundary is generated here and a caller-supplied Content-Type header must not survive, because a boundary that does not match these bytes yields a body the upstream parses as zero parts (issue #1296).
func Is ¶
Is reports whether contentType names multipart/form-data, ignoring any parameters (a boundary) and casing. An unparseable value falls back to comparing the text before the first ";" so a caller's malformed header still routes to the multipart encoder rather than being silently JSON-encoded under a multipart header.
Types ¶
This section is empty.