@@ -359,14 +359,14 @@ void WebServer::_uploadWriteByte(uint8_t b){
359359 _currentUpload->buf [_currentUpload->currentSize ++] = b;
360360}
361361
362- uint8_t WebServer::_uploadReadByte (WiFiClient& client){
362+ int WebServer::_uploadReadByte (WiFiClient& client){
363363 int res = client.read ();
364364 if (res == -1 ){
365365 while (!client.available () && client.connected ())
366366 delay (2 );
367367 res = client.read ();
368368 }
369- return ( uint8_t ) res;
369+ return res;
370370}
371371
372372bool WebServer::_parseForm (WiFiClient& client, String boundary, uint32_t len){
@@ -477,27 +477,28 @@ bool WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t len){
477477 if (_currentHandler && _currentHandler->canUpload (_currentUri))
478478 _currentHandler->upload (*this , _currentUri, *_currentUpload);
479479 _currentUpload->status = UPLOAD_FILE_WRITE;
480- uint8_t argByte = _uploadReadByte (client) ;
480+ int argByte;
481481readfile:
482- while (argByte != 0x0D ){
483- if (!client.connected ()) return _parseFormUploadAborted ();
484- _uploadWriteByte (argByte);
482+
483+ do {
485484 argByte = _uploadReadByte (client);
486- }
485+ if (argByte < 0 ) return _parseFormUploadAborted ();
486+ _uploadWriteByte (argByte);
487+ }while (argByte != 0x0D );
487488
488489 argByte = _uploadReadByte (client);
489- if (!client. connected () ) return _parseFormUploadAborted ();
490+ if (argByte < 0 ) return _parseFormUploadAborted ();
490491 if (argByte == 0x0A ){
491492 argByte = _uploadReadByte (client);
492- if (!client. connected () ) return _parseFormUploadAborted ();
493+ if (argByte < 0 ) return _parseFormUploadAborted ();
493494 if ((char )argByte != ' -' ){
494495 // continue reading the file
495496 _uploadWriteByte (0x0D );
496497 _uploadWriteByte (0x0A );
497498 goto readfile;
498499 } else {
499500 argByte = _uploadReadByte (client);
500- if (!client. connected () ) return _parseFormUploadAborted ();
501+ if (argByte < 0 ) return _parseFormUploadAborted ();
501502 if ((char )argByte != ' -' ){
502503 // continue reading the file
503504 _uploadWriteByte (0x0D );
0 commit comments