Skip to content

Commit 0063d80

Browse files
author
Me No Dev
committed
"Fix" sketches and libs to use the new upload api
1 parent 3e4418a commit 0063d80

File tree

4 files changed

+14
-21
lines changed

4 files changed

+14
-21
lines changed

libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,9 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server)
3636
_server->sendHeader("Access-Control-Allow-Origin", "*");
3737
_server->send(200, "text/plain", (Update.hasError())?"FAIL":"OK");
3838
ESP.restart();
39-
});
40-
41-
// handler for the file upload, get's the sketch bytes, and writes
42-
// them through the Update object.
43-
_server->onFileUpload([&](){
44-
if(_server->uri() != "/update") return;
39+
},[&](){
40+
// handler for the file upload, get's the sketch bytes, and writes
41+
// them through the Update object
4542
HTTPUpload& upload = _server->upload();
4643
if(upload.status == UPLOAD_FILE_START){
4744
if (_serial_output)
@@ -70,6 +67,6 @@ void ESP8266HTTPUpdateServer::setup(ESP8266WebServer *server)
7067
Update.end();
7168
if (_serial_output) Serial.println("Update was aborted");
7269
}
73-
yield();
70+
delay(0);
7471
});
7572
}

libraries/ESP8266WebServer/examples/FSBrowser/FSBrowser.ino

+3-4
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ void setup(void){
207207
server.on("/edit", HTTP_PUT, handleFileCreate);
208208
//delete file
209209
server.on("/edit", HTTP_DELETE, handleFileDelete);
210-
//called after file upload
211-
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); });
212-
//called when a file is received inside POST data
213-
server.onFileUpload(handleFileUpload);
210+
//first callback is called after the request has ended with all parsed arguments
211+
//second callback handles file uploads at that location
212+
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);
214213

215214
//called when the url is not defined here
216215
//use it to load content from SPIFFS

libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino

+1-2
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,8 @@ void setup(void){
256256
server.on("/list", HTTP_GET, printDirectory);
257257
server.on("/edit", HTTP_DELETE, handleDelete);
258258
server.on("/edit", HTTP_PUT, handleCreate);
259-
server.on("/edit", HTTP_POST, [](){ returnOK(); });
259+
server.on("/edit", HTTP_POST, [](){ returnOK(); }, handleFileUpload);
260260
server.onNotFound(handleNotFound);
261-
server.onFileUpload(handleFileUpload);
262261

263262
server.begin();
264263
DBG_OUTPUT_PORT.println("HTTP server started");

libraries/ESP8266WebServer/examples/WebUpdate/WebUpdate.ino

+6-8
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ void setup(void){
2727
server.sendHeader("Access-Control-Allow-Origin", "*");
2828
server.send(200, "text/html", serverIndex);
2929
});
30-
server.onFileUpload([](){
31-
if(server.uri() != "/update") return;
30+
server.on("/update", HTTP_POST, [](){
31+
server.sendHeader("Connection", "close");
32+
server.sendHeader("Access-Control-Allow-Origin", "*");
33+
server.send(200, "text/plain", (Update.hasError())?"FAIL":"OK");
34+
ESP.restart();
35+
},[](){
3236
HTTPUpload& upload = server.upload();
3337
if(upload.status == UPLOAD_FILE_START){
3438
Serial.setDebugOutput(true);
@@ -52,12 +56,6 @@ void setup(void){
5256
}
5357
yield();
5458
});
55-
server.on("/update", HTTP_POST, [](){
56-
server.sendHeader("Connection", "close");
57-
server.sendHeader("Access-Control-Allow-Origin", "*");
58-
server.send(200, "text/plain", (Update.hasError())?"FAIL":"OK");
59-
ESP.restart();
60-
});
6159
server.begin();
6260
MDNS.addService("http", "tcp", 80);
6361

0 commit comments

Comments
 (0)