diff --git a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp index 0057a2d1b..0b6d672e2 100644 --- a/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp +++ b/libraries/ESP8266WebServer/src/ESP8266WebServer.cpp @@ -441,8 +441,6 @@ readfile: argByte = client.read(); if(argByte == 0x0A){ - line = client.readStringUntil(0x0D); - client.readStringUntil(0x0A); #ifdef DEBUG DEBUG_OUTPUT.print("Write File: "); DEBUG_OUTPUT.println(_currentUpload.buflen); @@ -450,7 +448,28 @@ readfile: if(_fileUploadHandler) _fileUploadHandler(); _currentUpload.size += _currentUpload.buflen; _currentUpload.buflen = 0; - if(line.startsWith("--"+boundary)){ + + argByte = client.read(); + if((char)argByte != '-'){ + //continue reading the file + _currentUpload.buf[_currentUpload.buflen++] = 0x0D; + _currentUpload.buf[_currentUpload.buflen++] = 0x0A; + goto readfile; + } else { + argByte = client.read(); + if((char)argByte != '-'){ + //continue reading the file + _currentUpload.buf[_currentUpload.buflen++] = 0x0D; + _currentUpload.buf[_currentUpload.buflen++] = 0x0A; + _currentUpload.buf[_currentUpload.buflen++] = (uint8_t)('-'); + goto readfile; + } + } + + uint8_t endBuf[boundary.length()]; + client.readBytes(endBuf, boundary.length()); + + if(strstr((const char*)endBuf, (const char*)(boundary.c_str())) != NULL){ _currentUpload.status = UPLOAD_FILE_END; #ifdef DEBUG DEBUG_OUTPUT.print("End File: "); @@ -461,7 +480,9 @@ readfile: DEBUG_OUTPUT.println(_currentUpload.size); #endif if(_fileUploadHandler) _fileUploadHandler(); - if(line == ("--"+boundary+"--")){ + line = client.readStringUntil(0x0D); + client.readStringUntil(0x0A); + if(line == "--"){ #ifdef DEBUG DEBUG_OUTPUT.println("Done Parsing POST"); #endif @@ -471,10 +492,9 @@ readfile: } else { _currentUpload.buf[_currentUpload.buflen++] = 0x0D; _currentUpload.buf[_currentUpload.buflen++] = 0x0A; - const char * lineChars = line.c_str(); uint32_t i = 0; - while(i < os_strlen(lineChars)){ - _currentUpload.buf[_currentUpload.buflen++] = lineChars[i++]; + while(i < boundary.length()){ + _currentUpload.buf[_currentUpload.buflen++] = endBuf[i++]; if(_currentUpload.buflen == 1460){ #ifdef DEBUG DEBUG_OUTPUT.println("Write File: 1460");