@@ -441,16 +441,35 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
441
441
442
442
argByte = client.read ();
443
443
if (argByte == 0x0A ){
444
- line = client.readStringUntil (0x0D );
445
- client.readStringUntil (0x0A );
446
444
#ifdef DEBUG
447
445
DEBUG_OUTPUT.print (" Write File: " );
448
446
DEBUG_OUTPUT.println (_currentUpload.buflen );
449
447
#endif
450
448
if (_fileUploadHandler) _fileUploadHandler ();
451
449
_currentUpload.size += _currentUpload.buflen ;
452
450
_currentUpload.buflen = 0 ;
453
- if (line.startsWith (" --" +boundary)){
451
+
452
+ argByte = client.read ();
453
+ if ((char )argByte != ' -' ){
454
+ // continue reading the file
455
+ _currentUpload.buf [_currentUpload.buflen ++] = 0x0D ;
456
+ _currentUpload.buf [_currentUpload.buflen ++] = 0x0A ;
457
+ goto readfile;
458
+ } else {
459
+ argByte = client.read ();
460
+ if ((char )argByte != ' -' ){
461
+ // continue reading the file
462
+ _currentUpload.buf [_currentUpload.buflen ++] = 0x0D ;
463
+ _currentUpload.buf [_currentUpload.buflen ++] = 0x0A ;
464
+ _currentUpload.buf [_currentUpload.buflen ++] = (uint8_t )(' -' );
465
+ goto readfile;
466
+ }
467
+ }
468
+
469
+ uint8_t endBuf[boundary.length ()];
470
+ client.readBytes (endBuf, boundary.length ());
471
+
472
+ if (strstr ((const char *)endBuf, (const char *)(boundary.c_str ())) != NULL ){
454
473
_currentUpload.status = UPLOAD_FILE_END;
455
474
#ifdef DEBUG
456
475
DEBUG_OUTPUT.print (" End File: " );
@@ -461,7 +480,9 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
461
480
DEBUG_OUTPUT.println (_currentUpload.size );
462
481
#endif
463
482
if (_fileUploadHandler) _fileUploadHandler ();
464
- if (line == (" --" +boundary+" --" )){
483
+ line = client.readStringUntil (0x0D );
484
+ client.readStringUntil (0x0A );
485
+ if (line == " --" ){
465
486
#ifdef DEBUG
466
487
DEBUG_OUTPUT.println (" Done Parsing POST" );
467
488
#endif
@@ -471,10 +492,9 @@ void ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
471
492
} else {
472
493
_currentUpload.buf [_currentUpload.buflen ++] = 0x0D ;
473
494
_currentUpload.buf [_currentUpload.buflen ++] = 0x0A ;
474
- const char * lineChars = line.c_str ();
475
495
uint32_t i = 0 ;
476
- while (i < os_strlen (lineChars )){
477
- _currentUpload.buf [_currentUpload.buflen ++] = lineChars [i++];
496
+ while (i < boundary. length ( )){
497
+ _currentUpload.buf [_currentUpload.buflen ++] = endBuf [i++];
478
498
if (_currentUpload.buflen == 1460 ){
479
499
#ifdef DEBUG
480
500
DEBUG_OUTPUT.println (" Write File: 1460" );
0 commit comments