cpprest Casablanca doesn't close file stream

May 30 at 11:16 PM
i don't know the reason but my server doesn't work anymore. The problem is because it doesn't close the output file stream "uploaded",so i can't manage the file because it exists but it's empty. Suggestions?

void Server::handle_post(http_request request)
{ TRACE("\nhandle POST\n"); auto fileBuffer = std::make_shared>(); string_t uploaded = L"uploaded"; suffix++; std::wstringstream wss; wss << suffix << (".txt");

uploaded.append(wss.str());

try
{
auto stream = concurrency::streams::fstream::open_ostream(
    uploaded,
    std::ios_base::out | std::ios_base::binary).then([request, fileBuffer](pplx::task<Concurrency::streams::basic_ostream<unsigned char>> Previous_task)
{

    *fileBuffer = Previous_task.get();
    try
    {
        request.body().read_to_end(fileBuffer->streambuf()).get();
    }
    catch (const exception&)
    {
        wcout << L"<exception>" << std::endl;
        //return pplx::task_from_result();
    }
    //Previous_task.get().close();

}).then([=](pplx::task<void> Previous_task)
{


    fileBuffer->close();
    //Previous_task.get();
}).then([](task<void> previousTask)
{
    // This continuation is run because it is value-based.
    try
    {
        // The call to task::get rethrows the exception.

        previousTask.get();
    }
    catch (const exception& e)
    {
        wcout << e.what() << endl;
    }
});
//stream.get().close();
}
catch (const exception& e)
{
wcout << e.what() << endl;
}


ManageClient( uploaded);

request.reply(status_codes::OK, U("Hello, World!")).then([](pplx::task<void> t) { handle_error(t); });
return;
}