The Wayback Machine - https://web.archive.org/web/20200906234550/https://github.com/AndsonYe/MultipartEncoder
Skip to content
master
Go to file
Code

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
Mar 4, 2017
Jan 20, 2020
Mar 4, 2017
Mar 4, 2017
Mar 4, 2017

README.md

MultipartEncoder: A C++ implementation of encoding multipart/form-data

You may find the asynchronous http-client, i.e. cpprestsdk, does not support posting a multipart/form-data request. This MultipartEncoder is a work around to generate the body content of multipart/form-data format. So that then you can use a cpp HTTP-client, which is not limited to cpprestsdk, to post a multipart/form-data request by setting the encoded body content.

Build & Run

  1. Clone the MultipartEncoder repository

    # Make sure to clone with --recursive
    git clone --recursive https://github.com/AndsonYe/MultipartEncoder.git
  2. If not cloned with --recursive, you need to manually get the cpprestsdk submodle

    Ignore this step if you followed step 1 above.

    git submodule update --init --recursive
  3. Install dependencies required by cpprestsdk

    sudo apt-get install g++ git make zlib1g-dev libboost-all-dev libssl-dev cmake
  4. Build cpprestsdk. Suppose the directory you cloned MultipartEncoder into is MultipartEncoder_ROOT

    cd $MultipartEncoder_ROOT/cpprestsdk/Release
    mkdir build
    cd build
    cmake ..
    make -j$(nproc)
  5. Build MultipartEncoder sample

    cd $MultipartEncoder_ROOT
    make
  6. Run the sample

    ./run.sh

    The response is writtern in file $MultipartEncoder/results

Usage

MultipartParser parser;                             //Create parser instance;
parser.AddParameter(key, value);                    //Add text parameters using AddParameter
parser.AddFile(key, file_path);                     //Add file content using AddFile
std::string boundary = parser.boundary();           //Get the boundary generated by parser, each parser has its unique boundary, this boundary should be set in the HTTP request's header
std::string body = parser.GenBodyContent();         //Get the encoded multipart/form-data body content

Then you can use boundary and body in any HTTP clients.

Check the parser_test.cpp for complete example.

About

C++ implementation of encoding HTTP multipart/form-data into a string buffer for POST action in HTTP clients

Topics

Resources

License

Releases

No releases published

Packages

No packages published
You can’t perform that action at this time.