From ffa893f77077fae51fd7102046b47ba341a1ef3a Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Fri, 13 May 2016 00:01:42 +0300 Subject: [PATCH] Atempt at fixing large uploads Fixing: https://github.com/me-no-dev/ESPAsyncWebServer/issues/29 --- src/WebRequest.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/WebRequest.cpp b/src/WebRequest.cpp index b99e136..938fa46 100644 --- a/src/WebRequest.cpp +++ b/src/WebRequest.cpp @@ -316,7 +316,8 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data){ void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last){ _itemBuffer[_itemBufferIndex++] = data; - if(last){ + + if(last || _itemBufferIndex = 1460){ if(_handler) _handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false); _itemBufferIndex = 0; @@ -348,7 +349,13 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){ _itemType = String(); } - if(_multiParseState == EXPECT_BOUNDARY){ + if(_multiParseState == WAIT_FOR_RETURN1){ + if(data != '\r'){ + itemWriteByte(data); + } else { + _multiParseState = EXPECT_FEED1; + } + } else if(_multiParseState == EXPECT_BOUNDARY){ if(_parsedLength < 2 && data != '-'){ _multiParseState = PARSE_ERROR; return; @@ -407,16 +414,14 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){ if(_itemBuffer) free(_itemBuffer); _itemBuffer = (uint8_t*)malloc(1460); + if(_itemBuffer == NULL){ + _multiParseState = PARSE_ERROR; + return; + } _itemBufferIndex = 0; } } } - } else if(_multiParseState == WAIT_FOR_RETURN1){ - if(data != '\r'){ - itemWriteByte(data); - } else { - _multiParseState = EXPECT_FEED1; - } } else if(_multiParseState == EXPECT_FEED1){ if(data != '\n'){ _multiParseState = WAIT_FOR_RETURN1;