Re: Stream binary data to webclient without file object
Posted: Tue Sep 29, 2015 7:54 am
I think we have a sequence issue here. As far as is can see in the webserver class, the headers and content are both send with the final ::send method. You can do a SendHeader but it will only prepare it by adding to an internal string, it will not actually send it.
So if I try something like this:
WebServer.sendHeader("Content-Disposition", "attachment; filename=config.txt");
WebServer.setContentLength(2048);
client.write((const char*)data, 2048);
WebServer.send(200, "application/octet-stream", "");
all the headers are send after the data has been send and the browser does not understand the content.
It will not download to file but display the file contents and at the end the headers.
It seems I have to use something different then WebServer.send(200, "application/octet-stream", "") because you cannot send a header line after sending data...
So if I try something like this:
WebServer.sendHeader("Content-Disposition", "attachment; filename=config.txt");
WebServer.setContentLength(2048);
client.write((const char*)data, 2048);
WebServer.send(200, "application/octet-stream", "");
all the headers are send after the data has been send and the browser does not understand the content.
It will not download to file but display the file contents and at the end the headers.
It seems I have to use something different then WebServer.send(200, "application/octet-stream", "") because you cannot send a header line after sending data...