package piaf
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=00c3bea6d1a8c77dc18bbbbf1f449a78253cf17391ad153751b2e87f71307265
sha512=0f35e88b78ec1f1cd06a972ee69e29a8983b4c07dbc0268cc9764d8df5d9c2402cc3710874f54a111095fb57a08fe582d99d1b7e070e141e260af6ced50172aa
doc/piaf.multipart_form/Multipart_form/index.html
Module Multipart_form
Source
Multipart-form.
The MIME type multipart/form-data
is used to express values submitted through a <form>
. This module helps the user to extract these values from an input.
Type of emitters.
An emitters
is able to produce from the given header a pusher which is able to save contents and a unique ID to be able to get the content furthermore.
Type of a simple element.
An element is a part in sense of the multipart/form-data
format. A part can contains multiple parts. It has systematically a Header.t
.
Type of multipart/form-data
contents.
- a
Leaf
is a content with a simple header. - a
Multipart
is alist
of possibly empty (option
) sub-elements - indeed, we can have a multipart inside a multipart.
val parser :
emitters:'id emitters ->
Content_type.t ->
max_chunk_size:int ->
'id t Angstrom.t
parser ~emitters content_type
creates an angstrom
's parser which can process a multipart/form-data
input. For each Leaf
, the parser calls emitters
to be able to save contents and get a reference of it.
A simple use of it is to generate an unique ID and associate it to a Buffer.t
such as:
let gen = let v = ref (-1) in fun () -> incr v ; !v in
let tbl = Hashtbl.create 0x10 in
let emitters () =
let idx = gen () in
let buf = Buffer.create 0x100 in
(function None -> ()
| Some str -> Buffer.add_string buf str), idx in
parser ~emitters content_type
With such style, a mapping exists between the returned value t
and tbl
. At the end, the user is able to extract contents with these values.
In some contexts, something else such as an Lwt_stream.t
/asynchronous stream can be used instead a Buffer.t
.
val of_stream :
string stream ->
Content_type.t ->
(int t * (int * string) list, [> `Msg of string ]) result
of_stream stream content_type
returns, if it succeeds, a value t
with an associative list of unique ID and contents.
val of_string :
string ->
Content_type.t ->
(int t * (int * string) list, [> `Msg of string ]) result
of_string str content_type
returns, if it succeeds, a value t
with an associative list of unique ID and contents.
val part :
?header:Header.t ->
?disposition:Content_disposition.t ->
?encoding:Content_encoding.t ->
(string * int * int) stream ->
part