1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-12 01:53:07 +03:00

Add setContentLength method to web server, update examples

related to #304
This commit is contained in:
Ivan Grokhotkov
2015-05-22 17:57:30 +03:00
parent 21d50e104c
commit 8fdb824e11
4 changed files with 62 additions and 58 deletions

View File

@ -85,16 +85,9 @@ bool loadFromSdCard(String path){
if (!dataFile)
return false;
if(server.hasArg("download")) dataType = "application/octet-stream";
if (server.hasArg("download")) dataType = "application/octet-stream";
server.sendHeader("Content-Length", String(dataFile.size()));
server.sendHeader("Connection", "close");
server.sendHeader("Access-Control-Allow-Origin", "*");
server.send(200, dataType.c_str(), "");
WiFiClient client = server.client();
size_t totalSize = dataFile.size();
if (client.write(dataFile, HTTP_DOWNLOAD_UNIT_SIZE) != totalSize) {
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
DBG_OUTPUT_PORT.println("Sent less data than expected!");
}
@ -187,7 +180,7 @@ void printDirectory() {
return returnFail("NOT DIR");
}
dir.rewindDirectory();
server.setContentSize(CONTENT_SIZE_UNKNOWN);
server.send(200, "text/json", "");
WiFiClient client = server.client();