class EE::Network::Http::MultipartEntitiesBuilder

Overview

Helper class to build the body of a multipart/form-data request. More…

#include <http.hpp>

class MultipartEntitiesBuilder {
public:
    // construction

    MultipartEntitiesBuilder();
    MultipartEntitiesBuilder(const std::string& boundary);

    // methods

    std::string getContentType();
    const std::string& getBoundary() const;
    void addParameter(const std::string& name, const std::string& value);
    void addFile(const std::string& parameterName, const std::string& fileName, IOStream* stream);
    void addFile(const std::string& parameterName, const std::string& filePath);
    std::string build();
};

Detailed Documentation

Helper class to build the body of a multipart/form-data request.

Construction

MultipartEntitiesBuilder(const std::string& boundary)

Parameters:

boundary

The boundary to use in the multipart data.

Methods

std::string getContentType()

For example:

Http::Request request;
Http::MultipartEntitiesBuilder builder;
...
request.setField( "Content-Type", builder.getContentType() );

Returns:

The corresponding request Content-Type needed. This Content-Type header must be set to the request in order to work correctly.

const std::string& getBoundary() const

Returns:

The boundary used to build the multipart data.

void addParameter(const std::string& name, const std::string& value)

Adds a text multipart form field.

void addFile(const std::string& parameterName, const std::string& fileName, IOStream* stream)

Adds a file to the multipart data.

Parameters:

parameterName

The field name.

fileName

The file name of the stream.

stream

The stream were the file is located and is going to be read.

void addFile(const std::string& parameterName, const std::string& filePath)

Adds a file to the multipart data.

Parameters:

parameterName

The field name.

filePath

The local file path.