Saving http_request.body() to file

Dec 4, 2014 at 7:53 AM
Edited Dec 4, 2014 at 11:49 AM
I'm trying save raw body of POST request (using http_listener),
but calling: request.body().read_to_end(stream.streambuf()).wait();
never returns;

my test code:

void processPost(http_request &request) {
auto stream = concurrency::streams::fstream::open_ostream(
    std::ios_base::out | std::ios_base::binary).get();

request.body().read_to_end(stream.streambuf()).wait(); // never returns

Interesting fact:

if i call request.extract_vector().get(), and save vector byte by byte to file - everything works fine.

edit: i'm using debian 64-bit
Dec 5, 2014 at 1:59 AM
Hi arekmarud,

I wrote a test similar to what you describe and indeed encounter the bug using Ubuntu 64bit debug. I've opened a bug on Codeplex to track this. For now a workaround is to use http_request::extract_vector or http_request::extract_string and then write the data to the file. I would recommend write in chunks or all at once though, byte by byte would be terribly slow.

Thanks for reporting the issue,
Feb 1 at 6:43 PM
i'm interested in write similar code but i didn't fine enough doc about it.
In particular i made a client POST where i send a file and from server side i need to extract not only the byte but also the name of the file because i need to open a file from server side with the same name.
Could you help me?
Apr 11 at 12:34 PM
auto fileBuffer = std::make_shared<Concurrency::streams::basic_ostream<uint8_t>>();
    auto stream = concurrency::streams::fstream::open_ostream(
        std::ios_base::out | std::ios_base::binary).then([request,fileBuffer](pplx::task<Concurrency::streams::basic_ostream<uint8_t>> Previous_task)

        *fileBuffer = Previous_task.get();

It works.
The point is ...if i have multiple concurrency POST request is there an issue if i have multiple open_ostream on data.txt?