Merge pull request #2393 from hunbernd/fix/WebUI-binary-files

Fix: WebUI truncating binary files
This commit is contained in:
csoler 2021-03-26 20:15:33 +01:00 committed by GitHub
commit e22e1c1a8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -76,21 +76,21 @@ public:
std::string resource_filename = _base_directory + "/" + directory + filename;
RsDbg() << "Reading file: \"" << resource_filename << "\"" << std::endl;
std::ifstream stream( resource_filename, std::ifstream::in );
std::ifstream stream( resource_filename, std::ifstream::binary);
if(stream.is_open())
{
const std::string body = std::string(
const std::vector<uint8_t> body = std::vector<uint8_t>(
std::istreambuf_iterator<char>(stream),
std::istreambuf_iterator<char>() );
RsDbg() << __PRETTY_FUNCTION__
<< " body length=" << body.length() << std::endl;
<< " body length=" << body.size() << std::endl;
const std::multimap<std::string, std::string> headers
{
{ "Content-Type", mime_types[MIME_TYPE_INDEX] },
{ "Content-Length", std::to_string(body.length()) }
{ "Content-Length", std::to_string(body.size()) }
};
session->close(restbed::OK, body, headers);