View Source Multipart.Part (Multipart v0.4.0)

Represents an individual part of a Multipart message.

Link to this section Summary

Functions

Builds a Part with a binary body.

Builds a Part with a streaming file body.

Builds a form-data Part with an in-memory file body.

Builds a form-data Part with a streaming file body.

Builds a Part with a Stream body.

Builds a form-data Part with a streaming body.

Builds a form-data Part with a text body.

Link to this section Types

@type body() :: binary() | Enum.t()
@type headers() :: [{binary(), binary()}]
@type name() :: String.t() | atom()
@type t() :: %Multipart.Part{
  body: body(),
  content_length: pos_integer() | nil,
  headers: []
}

Link to this section Functions

Link to this function

binary_body(body, headers \\ [])

View Source
@spec binary_body(binary(), headers()) :: t()

Builds a Part with a binary body.

Set the content_length of the Part to the length of the binary.

Link to this function

file_body(path, headers \\ [])

View Source
@spec file_body(String.t(), headers()) :: t()

Builds a Part with a streaming file body.

Set the content_length of the Part to the size of the file on disk, as inspected with File.stat.

Link to this function

file_content_field(path, content, name, headers \\ [], opts \\ [])

View Source

Builds a form-data Part with an in-memory file body.

Takes the following Keyword options in opts:

  • filename: controls the inclusion of the filename="foo" directive in the content-disposition header. Defaults to true, which uses the filename from the path on disk. Pass in a String to override this, or set to false to disable this directive.

  • content_type: controls the inclusion of the content-type header. Defaults to true which will use MIME.from_path/1 to detect the mime type of the file. Pass in a String to override this, or set to false to disable this header.

Link to this function

file_field(path, name, headers \\ [], opts \\ [])

View Source
@spec file_field(String.t(), name(), headers(), Keyword.t()) :: t()

Builds a form-data Part with a streaming file body.

Takes the following Keyword options in opts:

  • filename: controls the inclusion of the filename="foo" directive in the content-disposition header. Defaults to true, which uses the filename from the path on disk. Pass in a String to override this, or set to false to disable this directive.

  • content_type: controls the inclusion of the content-type header. Defaults to true which will use MIME.from_path/1 to detect the mime type of the file. Pass in a String to override this, or set to false to disable this header.

Link to this function

stream_body(stream, headers \\ [])

View Source
@spec stream_body(Enum.t(), headers()) :: t()

Builds a Part with a Stream body.

Because the length of the Stream cannot be known up front it doesn't define the content_length. This will cause Multipart.content_length/1 to error unless you set the content_length manually in the struct.

Link to this function

stream_field(stream, name, headers \\ [])

View Source
@spec stream_field(Enum.t(), name(), headers()) :: t()

Builds a form-data Part with a streaming body.

Link to this function

text_field(body, name, headers \\ [])

View Source
@spec text_field(binary(), name(), headers()) :: t()

Builds a form-data Part with a text body.