Crow/docs/guides/multipart.md
The-EDev 23648445f3 Changed documentation. a lot.
Added mkdocs documentation.
Altered doxygen generation (doxyfile and shell script) to work with mkdocs.
Removed the whole html folder thing for docs, now the files reside in the root gh-pages branch.
New readme.
2020-11-28 17:28:47 +03:00

1.6 KiB

Multipart is a way of forming HTTP requests or responses to contain multiple distinct parts.
Such an approach allows a request to contain multiple different pieces of data with potentially conflicting data types in a single response payload.
It is typically used either in html forms, or when uploading multiple files.

The structure of a multipart request is typically consistent of:

  • A Header: Typically multipart/form-data;boundary=<boundary>, This defines the HTTP message as being multipart, as well as defining the separator used to distinguish the different parts.
  • 1 or more parts:
    • --<boundary>
    • Part header: typically content-disposition: mime/type; name="<fieldname>" (mime/type should be replaced with the actual mime-type), can also contain a filename property (separated from the rest by a ; and structured similarly to the name property)
    • Value
  • --<boundary>--

Crow supports multipart requests and responses though crow::multipart::message.
A message can be created either by defining the headers, boundary, and individual parts and using them to create the message. or simply by reading a crow::request.

Once a multipart message has been made, the individual parts can be accessed throught mpmes.parts, parts is an std::vector, so accessing the individual parts should be straightforward.
In order to access the individual part's name or filename, something like #!cpp mpmes.parts[0].headers[0].params["name"] sould do the trick.

For more info on Multipart messages, go here