Quantcast
Channel: WE MOVED to github.com/microsoft/cpprestsdk. This site is not monitored!
Viewing all articles
Browse latest Browse all 4845

New Post: access image file from the server side (http_listener) .

$
0
0
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);

Viewing all articles
Browse latest Browse all 4845

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>