pistacheio / pistache

A high-performance REST toolkit written in C++
https://pistacheio.github.io/pistache/
Apache License 2.0
3.12k stars 690 forks source link

How can I extract binary data from request? #1096

Open softwaremarkdahl opened 1 year ago

softwaremarkdahl commented 1 year ago

I'm trying to receive a file upload to pistache from a web page using multipart/form-data. Pistache receive the data, but it seems to me I can only get the string data part of the body in the post. How can I retrieve the binary part (that is the file sent by the form)?

dennisjenkins75 commented 1 year ago

Pistache does not include any mime-defang logic. You'll need to write your own or use a third party library.

softwaremarkdahl commented 1 year ago

Thanks for the reply. I know I'll have to manage the mime in other way, but it's not clear to me if it's possible to extract the multipart binary data from the request.

Fabio3rs commented 1 year ago

I did a test here with a multipart form sending a 160KB zero-filled file and it seems ok, the non-text binary seems ok in the body.

image

Saving the body to analyze:

std::fstream dump("dump.bin", std::ios::out | std::ios::trunc);
    dump.write(request.body().c_str(),
               static_cast<std::streamsize>(request.body().size()))
        << std::endl;

Inspecting:

hexdump -vC dump.bin | less