Stream binary data to webclient without file object
Posted: Mon Sep 28, 2015 12:03 pm
I'm looking for a way to send binary data to the webclient (browser) to download to file.
This code snippet works to have some string data saved to file using your browser:
String reply = "this is a demo string";
WebServer.sendHeader("Content-Disposition", "attachment; filename=settings.txt");
WebServer.send(200, "application/octet-stream", reply);
and this snippet works for sending a file on SPIFFS:
dataType = F("application/octet-stream");
File dataFile = SPIFFS.open(path.c_str(), "r");
WebServer.sendHeader("Content-Disposition", "attachment;");
WebServer.streamFile(dataFile, dataType);
But I would like to send a byte array from memory to the webbrowser, so I guess that I would need something like:
WebServer.StreamData(byte* data, int datasize)
Is there a method of sending binary data without using StreamFile ?
I can convert the binary data to hex string beforehand, but this is not what I want because it doubles the filesize.
Does anyone have a sample code on how to achieve this?
This code snippet works to have some string data saved to file using your browser:
String reply = "this is a demo string";
WebServer.sendHeader("Content-Disposition", "attachment; filename=settings.txt");
WebServer.send(200, "application/octet-stream", reply);
and this snippet works for sending a file on SPIFFS:
dataType = F("application/octet-stream");
File dataFile = SPIFFS.open(path.c_str(), "r");
WebServer.sendHeader("Content-Disposition", "attachment;");
WebServer.streamFile(dataFile, dataType);
But I would like to send a byte array from memory to the webbrowser, so I guess that I would need something like:
WebServer.StreamData(byte* data, int datasize)
Is there a method of sending binary data without using StreamFile ?
I can convert the binary data to hex string beforehand, but this is not what I want because it doubles the filesize.
Does anyone have a sample code on how to achieve this?