View Source Multipart (Multipart v0.4.0)
Multipart
constructs multipart messages.
It aims to produce multipart messages that are compatible with RFC
2046 for general use, and
RFC 7578 for constructing
multipart/form-data
requests.
Link to this section Summary
Link to this section Types
@type t() :: %Multipart{boundary: String.t(), parts: [Multipart.Part.t()]}
Link to this section Functions
@spec add_part(t(), Multipart.Part.t()) :: t()
Adds a part to the Multipart
message.
Returns a binary of the Multipart
message body.
This uses body_stream/1
under the hood.
@spec content_length(t()) :: pos_integer()
Returns the length of the Multipart
message in bytes.
It uses the content_length
property in each of the message parts to
calculate the length of the multipart message without reading the entire
body into memory. content_length
is set on the Multipart.Part
by the
constructor functions when possible, such as when the in-memory binary
or the file on disk can be inspected.
This will throw an error if any of the parts does not have content_length
defined.
Returns the Content-Type header for the Multipart
message.
iex> multipart = Multipart.new("==abc123==")
iex> Multipart.content_type(multipart, "multipart/mixed")
"multipart/mixed; boundary=\"==abc123==\""
Create a new Multipart
request.
Pass in the boundary as the first argument to set it explicitly, otherwise
it will default to a random 16 character alphanumeric string padded by ==
on either side.