Send PDF to Clients

Dec 4, 2015 at 5:38 AM
Hi guys,

i need a possibillity to send PDF Files to my Clients from a REST service.

Is it possible to do this with casablanca as Json object or is there a better way?
Please sende an example.


Dec 10, 2015 at 11:12 AM
Edited Dec 10, 2015 at 11:13 AM
Hi Cazzador,

Yes it's possible to do this without encoding binary data inside json.

You can open an asynchronous file stream using fstream::open_istream in order to read the data from disk.

Then you create a http_request, and and pass the file stream in via the set_body api.

Then you use a http_client to send the request.

Not sure if the code below compiles but it gives you a rough outline of what to do.

fstream::open_istream(fileNameWithFullPath).then([](pplx::task<istream> inFileTask)
   auto stream = inFileTask.get();
   http_client client http_client ("");
   http_request request;

   client.request(request).then([](pplx::task<http_response> responseTask)
       http::http_response response = responseTask.get();
       auto contentType = response.headers().content_type();
       // etc...

You might need to pay around with content type, content size etc..
Dec 18, 2015 at 4:52 PM
Thanks for the example.
My service will grow and grow :D
Feb 14, 2016 at 4:53 PM
Edited Feb 27, 2016 at 3:01 AM

i wrote the following code in my server app.
Can you tell me, how i can send the file to the requesting client?
json::value GetRequest::GetDocumentFromContentFolder(int ClientID, string FileName){

    jsonResponse[L"ClientID"] = ClientID;

    string FullFileName = Clients::GetInstance()->GetClientFolder(ClientID, Client::FolderType::Sammelordner) + '\\' + FileName;
    Directorymanagement *dir = new Directorymanagement();

    int i;
    if (dir->FileExists((char*)FullFileName.c_str()))

         std::ifstream ifs;

   , std::ifstream::binary);
             Request::request->set_body(? ? ? );//Requesting Client 
         catch (exception ex){

        Request::jsonResponse[L"Error"] = 0;
        Request::jsonResponse[L"Description"] = json::value(utility::conversions::to_string_t("Could not handel request, file not in the collectionfoulder found. Name " + FileName));

    return Request::jsonResponse;