MultipartParser API

size_t formMultipartParser(HttpRequest &request, const char *at, int length)

Body parser for content-type form-data/multipart

Must be added to the web server’s list of body parsers explicitly:

#include <MultipartParser.h>
HttpServer server;
server.setBodyParser(MIME_FORM_MULTIPART, formMultipartParser);

class HttpMultipartResource : public HttpResource

HttpResource that allows handling of HTTP file upload.

Public Functions

HttpMultipartResource(const HttpFilesMapper &mapper, HttpResourceDelegate complete)

Create and configure a HttpResource for handling file upload.

On a normal computer the file uploads are usually using temporary space on the hard disk or in memory to store the incoming data. On an embedded device that is a luxury that we can hardly afford. Therefore we should define a map that specifies explicitly where every form field will be stored. If a field is not specified then its content will be discarded.

  • mapper: callback that provides information where the desired upload fields will be stored.
  • complete: callback that will be called after the request has completed.

virtual int setFileMap(HttpServerConnection &connection, HttpRequest &request, HttpResponse &response)

Callback implementation for HttpResource::onHeadersComplete. Not to be used by application code.

void shutdown(HttpServerConnection &connection)

Takes care to cleanup the connection.

Public Members

HttpServerConnectionBodyDelegate onBody = nullptr

resource wants to process the raw body data

HttpResourceDelegate onHeadersComplete = nullptr

headers are ready

HttpResourceDelegate onRequestComplete = nullptr

request is complete OR upgraded

HttpServerConnectionUpgradeDelegate onUpgrade = nullptr

request is upgraded and raw data is passed to it