View Source hackney_multipart (hackney v1.23.0)

module to encode/decode multipart

Summary

Functions

decode a multipart form.
encode a list of parts a multipart form. Parts can be under the form:
  • {file, Path} : to send a file
  • {file, Path, ExtraHeaders} : to send a file with extra headers
  • {file, Path, Name, ExtraHeaders}: to send a file with DOM element name and extra headers
  • {mp_mixed, Name, Boundary} to send a mixed multipart.
  • {mp_mixed_eof, Boundary}: to signal the end of the mixed multipart boundary.
  • {Name, Data}: to send a custom content as a part
  • {Name, Data, ExtraHeaders}: the same as above but with extra headers.

get the size of a mp stream. Useful to calculate the content-length of a full multipart stream and send it as an identity transfer-encoding instead of chunked so any server can handle it.

return the multipart header for a data
return the boundary ending a multipart
return the multipart header for a file that will be sent later
create a generic multipart header
return the mixed multipart header
Return a multipart parser for the given boundary.

Types

body_cont/0

-type body_cont() :: cont(more(body_result())).

body_result/0

-type body_result() :: {body, binary(), body_cont()} | end_of_part().

cont/1

-type cont(T) :: fun(() -> T).

end_of_part/0

-type end_of_part() :: {end_of_part, cont(more(part_result()))}.

headers/0

-type headers() :: {headers, http_headers(), body_cont()}.

http_headers/0

-type http_headers() :: [{binary(), binary()}].

more/1

-type more(T) :: T | {more, parser(T)}.

parser/1

-type parser(T) :: fun((binary()) -> T).

part_parser/0

-type part_parser() :: parser(more(part_result())).

part_result/0

-type part_result() :: headers() | eof.

pattern/0

-type pattern() :: {binary:cp(), non_neg_integer()}.

patterns/0

-type patterns() :: {pattern(), pattern()}.

Functions

boundary()

-spec boundary() -> binary().

decode_form(Boundary, Body)

-spec decode_form(binary(), binary()) -> {ok, list()} | {error, term()}.
decode a multipart form.

encode_form(Parts)

encode a list of parts a multipart form. Parts can be under the form:
  • {file, Path} : to send a file
  • {file, Path, ExtraHeaders} : to send a file with extra headers
  • {file, Path, Name, ExtraHeaders}: to send a file with DOM element name and extra headers
  • {mp_mixed, Name, Boundary} to send a mixed multipart.
  • {mp_mixed_eof, Boundary}: to signal the end of the mixed multipart boundary.
  • {Name, Data}: to send a custom content as a part
  • {Name, Data, ExtraHeaders}: the same as above but with extra headers.

encode_form(Parts, Boundary)

-spec encode_form(list(), binary()) -> {binary(), integer()}.

len_mp_stream(Parts, Boundary)

get the size of a mp stream. Useful to calculate the content-length of a full multipart stream and send it as an identity transfer-encoding instead of chunked so any server can handle it.

Calculated Parts can be under the form:
  • {file, Path} : to send a file
  • {file, Path, ExtraHeaders} : to send a file with extra headers
  • {file, Path, Name, ExtraHeaders} : to send a file with DOM element name and extra headers
  • {mp_mixed, Name, Boundary} to send a mixed multipart. multipart boundary.
  • {Name, DataLen}: to send a custom content as a part
  • {Name, DataLen, ExtraHeaders}: the same as above but with extra headers.

mp_data_header(_, Boundary)

-spec mp_data_header({Name :: binary(), DataLen :: integer()} |
                     {Name :: binary(), DataLen :: integer(), ExtraHeaders :: [{binary(), binary()}]} |
                     {Name :: binary(),
                      DataLen :: integer(),
                      {Disposition :: binary(), Params :: [{binary(), binary()}]},
                      ExtraHeaders :: [{binary(), binary()}]},
                     Boundary :: binary()) ->
                        {binary(), DataLen :: integer()}.
return the multipart header for a data

mp_eof(Boundary)

return the boundary ending a multipart

mp_file_header(_, Boundary)

-spec mp_file_header({file, Path :: binary()} |
                     {file, Path :: binary(), ExtraHeaders :: [{binary(), binary()}]} |
                     {file, Path :: binary(), Name :: binary(), ExtraHeaders :: [{binary(), binary()}]} |
                     {file,
                      Path :: binary(),
                      {Disposition :: binary(), Params :: [{binary(), binary()}]},
                      ExtraHeaders :: [{binary(), binary()}]},
                     Boundary :: binary()) ->
                        {binary(), FileSize :: integer()}.
return the multipart header for a file that will be sent later

mp_header(Headers, Boundary)

create a generic multipart header

mp_mixed_header(_, Boundary)

-spec mp_mixed_header({Name :: binary(), MixedBoundary :: binary()}, Boundary :: binary()) ->
                         {binary(), 0}.
return the mixed multipart header

parser(Boundary)

-spec parser(binary()) -> part_parser().
Return a multipart parser for the given boundary.

part(Content, Headers, Boundary)

create a part