Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Fix file upload handler by adjusting function signatures #9

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncJson_Teensy41.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Expand Down
8 changes: 8 additions & 0 deletions src/AsyncWebHandlerImpl_Teensy41.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
5 changes: 3 additions & 2 deletions src/AsyncWebRequest_Teensy41.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/AsyncWebServer_Teensy41.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -697,7 +697,7 @@ class AsyncWebServerResponse
* */

typedef std::function<void(AsyncWebServerRequest *request)> ArRequestHandlerFunction;
typedef std::function<void(AsyncWebServerRequest *request, /*const String& filename,*/ size_t index, uint8_t *data, size_t len, bool final)> ArUploadHandlerFunction;
typedef std::function<void(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final)> ArUploadHandlerFunction;
typedef std::function<void(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)> ArBodyHandlerFunction;

/////////////////////////////////////////////////////////
Expand Down