diff --git a/changelog.md b/changelog.md index bdd0d63..0181cc0 100644 --- a/changelog.md +++ b/changelog.md @@ -28,6 +28,11 @@ ## Changelog +### Releases v1.7.0 + +1. Fix file upload to Teensy 4.1 board based on suggestions made on the PJRC forum. Align signatures of file upload handlers. +For more details, please see this post: [AsyncWebServer_Teensy41 bug onUpload](https://forum.pjrc.com/index.php?threads/asyncwebserver_teensy41-bug-onupload.72220). + ### Releases v1.6.2 1. Add examples [Async_WebSocketsServer](https://github.com/khoih-prog/AsyncWebServer_Teensy41/tree/main/examples/Async_WebSocketsServer) to demo how to use `Async_WebSockets` diff --git a/src/AsyncJson_Teensy41.h b/src/AsyncJson_Teensy41.h index 5727af0..eaf82f0 100644 --- a/src/AsyncJson_Teensy41.h +++ b/src/AsyncJson_Teensy41.h @@ -405,7 +405,7 @@ class AsyncCallbackJsonWebHandler: public AsyncWebHandler ///////////////////////////////////////////////// - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, + virtual void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) override final { } diff --git a/src/AsyncWebHandlerImpl_Teensy41.h b/src/AsyncWebHandlerImpl_Teensy41.h index 8fb32b3..92762f1 100644 --- a/src/AsyncWebHandlerImpl_Teensy41.h +++ b/src/AsyncWebHandlerImpl_Teensy41.h @@ -193,6 +193,14 @@ class AsyncCallbackWebHandler: public AsyncWebHandler ///////////////////////////////////////////////// + virtual void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) override final + { + if (_onUpload) + _onUpload(request, filename, index, data, len, final); + } + + ///////////////////////////////////////////////// + virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final { diff --git a/src/AsyncWebRequest_Teensy41.cpp b/src/AsyncWebRequest_Teensy41.cpp index aa23458..2ab367f 100644 --- a/src/AsyncWebRequest_Teensy41.cpp +++ b/src/AsyncWebRequest_Teensy41.cpp @@ -587,9 +587,10 @@ void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last) if (last || _itemBufferIndex == 1460) { //check if authenticated before calling the upload - if (_handler) + if (_handler) + { _handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false); - + } _itemBufferIndex = 0; } } diff --git a/src/AsyncWebServer_Teensy41.hpp b/src/AsyncWebServer_Teensy41.hpp index 9b295e9..ae632a3 100644 --- a/src/AsyncWebServer_Teensy41.hpp +++ b/src/AsyncWebServer_Teensy41.hpp @@ -629,7 +629,7 @@ class AsyncWebHandler ///////////////////////////////////////////////// virtual void handleRequest(AsyncWebServerRequest *request __attribute__((unused))) {} - virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), const String& filename __attribute__((unused)), + virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), String filename __attribute__((unused)), size_t index __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)), bool final __attribute__((unused))) {} virtual void handleBody(AsyncWebServerRequest *request __attribute__((unused)), uint8_t *data __attribute__((unused)), @@ -697,7 +697,7 @@ class AsyncWebServerResponse * */ typedef std::function ArRequestHandlerFunction; -typedef std::function ArUploadHandlerFunction; +typedef std::function ArUploadHandlerFunction; typedef std::function ArBodyHandlerFunction; /////////////////////////////////////////////////////////