Closed tobiasfaust closed 2 months ago
Maybe it's a watchdog time-out because server->on(...) wants a fast return. Make a separate thread to upload files, and trigger it from handleFiles::handleUpload, passing the parameters. For example, put request data in a struct and pass it (as reference) to a Ticker (separate library) callback.
Hi,
Thanks for your answer. Are you sure of a watchdog Issue? To prevent that I inserted the rtc_wdt_feed();
The HEAP Issue seems like a buffer overflow…..
Hi Tobias,
I agree it shows a heap error and I'm not sure it's a watchdog timer issue. I only know there are limits on how much can be done in a call back.
I make the suggestion because it solved a similar problem for my application. And it gives flexibility to process the uploads individually to reduce heap usage. Maybe also take a look at chunked response in the readme.
This great library has not been updated in a long time so you may have to find your own work around.
solved my myself ;)
i opened permanently AsyncResponseStream *response = request->beginResponseStream("text/json");
without using that. Solution is to move that code-fragment into final if-case.
That shows the problem, this call allocates memory without give free if it not used
final solution function:
void handleFiles::handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) { String logmessage = "Client:" + request->client()->remoteIP().toString() + " " + request->url(); Serial.println(logmessage); if (!index) { // open the file on first call and store the file handle in the request object request->_tempFile = LittleFS.open("/" + filename, "w"); Serial.printf("Upload Start: %s\n", filename.c_str()); } if (len) { // stream the incoming chunk to the opened file request->_tempFile.write(data, len); rtc_wdt_feed(); Serial.printf("Writing file: %s ,index=%d len=%d bytes\n", filename.c_str(), index, len); } if (final) { AsyncResponseStream *response = request->beginResponseStream("text/json"); response->addHeader("Server","ESP Async Web Server"); // close the file handle as the upload is now done request->_tempFile.close(); Serial.printf("Upload Complete: %s ,size: %d Bytes\n", filename.c_str(), (index + len)); } }
Hi, I'm using a simple fileupload to littleFS partition.
With only one file it works perfectly, but if i want to upload multiple files by selectiong a directory, the esp crashes after uploadfing 1-2 files
@me-no-dev do you have any suggestions?