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

Functions

Adds a part to the Multipart message.

Returns a binary of the Multipart message body.

Returns a Stream of the Multipart message body.

Returns the length of the Multipart message in bytes.

Returns the Content-Type header for the Multipart message.

Link to this section Types

@type t() :: %Multipart{boundary: String.t(), parts: [Multipart.Part.t()]}

Link to this section Functions

Link to this function

add_part(multipart, part)

View Source
@spec add_part(t(), Multipart.Part.t()) :: t()

Adds a part to the Multipart message.

@spec body_binary(t()) :: binary()

Returns a binary of the Multipart message body.

This uses body_stream/1 under the hood.

@spec body_stream(t()) :: Enum.t()

Returns a Stream of the Multipart message body.

Link to this function

content_length(multipart)

View Source
@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.

Link to this function

content_type(multipart, mime_type)

View Source
@spec content_type(t(), String.t()) :: String.t()

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==\""
Link to this function

new(boundary \\ generate_boundary())

View Source
@spec new(String.t()) :: t()

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.