20 #include "../../../include/esp3d_config.h"
21 #if defined (HTTP_FEATURE) && defined(WEB_UPDATE_FEATURE)
22 #include "../http_server.h"
23 #if defined (ARDUINO_ARCH_ESP32)
24 #include <WebServer.h>
27 #endif //ARDUINO_ARCH_ESP32
28 #if defined (ARDUINO_ARCH_ESP8266)
29 #include <ESP8266WebServer.h>
30 #define UPDATE_SIZE ESP_FileSystem::max_update_size()
31 #endif //ARDUINO_ARCH_ESP8266
32 #include "../../filesystem/esp_filesystem.h"
33 #include "../../authentication/authentication_service.h"
34 #include "../../../core/esp3doutput.h"
36 void HTTP_Server::WebUpdateUpload ()
38 static size_t last_upload_update;
39 static uint32_t downloadsize = 0;
45 output.printERROR(
"Update rejected!",401);
48 HTTPUpload& upload = _webserver->upload();
51 if(upload.status == UPLOAD_FILE_START) {
52 output.printMSG(
"Update Firmware");
54 String sizeargname = upload.filename +
"S";
55 if (_webserver->hasArg (sizeargname.c_str()) ) {
56 downloadsize = _webserver->arg (sizeargname).toInt();
62 output.printERROR(
"Update rejected!",500);
65 last_upload_update = 0;
67 if(!Update.begin(UPDATE_SIZE)) {
69 output.printERROR(
"Update rejected!",500);
72 output.printMSG(
"Update 0%");
76 }
else if(upload.status == UPLOAD_FILE_WRITE) {
80 if (downloadsize != 0) {
81 if ( ((100 * upload.totalSize) / downloadsize) !=last_upload_update) {
82 if ( downloadsize > 0) {
83 last_upload_update = (100 * upload.totalSize) / downloadsize;
85 last_upload_update = upload.totalSize;
88 s+= String(last_upload_update);
90 output.printMSG(s.c_str());
93 if(Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
95 output.printERROR(
"Update write failed!",500);
101 }
else if(upload.status == UPLOAD_FILE_END) {
102 if ((downloadsize!=0) && (downloadsize < upload.totalSize)) {
104 output.printERROR(
"Update write failed!",500);
108 if(Update.end(
true)) {
110 output.printMSG(
"Update 100%");
113 output.printERROR(
"Update failed!",500);
119 output.printERROR(
"Update failed!", 500);
123 output.printERROR(
"Update failed!",500);
133 #endif //HTTP_FEATURE && WEB_UPDATE_FEATURE