[Cppcms-users] HTTP response and binary stream (libharu)
Brought to you by:
artyom-beilis
|
From: augustin <aug...@ov...> - 2015-09-17 10:09:30
|
Hello,
I am asking here about returning a stream of data representing a PDF document.
I could ask the same question about returning a dynamically generated image,
using a third party library but returning the image with a cppcms application.
I am trying to get my cppcms application to output a PDF file (using libharu).
However, I seem to have a problem returning the binary output.
It seems that the cppcms internals are corrupting the stream.
I have tested separately libharu and it works Ok.
When I integrate the code into my cppcms application, I get a corrupted file.
I am not sure which way exist to return a
// Raw mode, returning simple HTTP headers:
app()->response().io_mode(cppcms::http::response::io_mode_type::raw);
// content type: PDF.
app()->response().out() << "Content-type: application/pdf\r\n";
app()->response().out() << "\r\n";
HPDF_Doc pdf // Create new PDF object.
HPDF_SaveToStream (pdf);
std::ostringstream cppcms_buf(std::ios::binary);
cppcms_buf.imbue(app()->context().locale());
for (;;) {
HPDF_BYTE buf[4096];
HPDF_UINT32 siz = 4096;
HPDF_ReadFromStream (pdf, buf, &siz);
//app()->response().out() << buf << std::flush;
if (siz == 0)
break;
cppcms_buf << buf;
}
// Getting a cppcms::http::response:
app()->response().out() << cppcms_buf.str();
I don't know if Artyom is still maintaining this project. I hope that either
he or someone else can tell me whether it's possible.
thanks,
augustin.
|