Trying to help but I only have example of opposite direction. The concepts are similar. This is slightly Windows C++ specific.
FILE *f;
errno_t e = fopen_s(&f, fn.c_str(), "rb"); // fn is filename in string_t
if (e)
return(web::http::status_codes::NotFound);
else
{
if (fseek(f, 0L, SEEK_END) == -1L)
return(web::http::status_codes::LengthRequired);
size_t l = ftell(f);
if (l == -1L)
return(web::http::status_codes::LengthRequired);
if (fseek(f, 0L, SEEK_SET) == -1L)
return(web::http::status_codes::LengthRequired);
std::vector<unsigned char> v(l);
if (l != std::fread(&v[0], 1, v.size(), f))
return(web::http::status_codes::LengthRequired);
fclose(f);
web::http::http_response r(web::http::status_codes::OK);
r.headers().add(U("Content-Type", U("image/gif"); // needed for browser to display image, otherwise notifies of download (tested on Firefox)
r.set_body(v);
message.reply(r);