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

Commit f508f2f

Browse files
authored
Merge pull request #9 from edwinvp/upload_file_fixes
Fix file upload handler by adjusting function signatures
2 parents d7b7d98 + a9653d0 commit f508f2f

5 files changed

+19
-5
lines changed

changelog.md

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828

2929
## Changelog
3030

31+
### Releases v1.7.0
32+
33+
1. Fix file upload to Teensy 4.1 board based on suggestions made on the PJRC forum. Align signatures of file upload handlers.
34+
For more details, please see this post: [AsyncWebServer_Teensy41 bug onUpload](https://forum.pjrc.com/index.php?threads/asyncwebserver_teensy41-bug-onupload.72220).
35+
3136
### Releases v1.6.2
3237

3338
1. Add examples [Async_WebSocketsServer](https://github.com/khoih-prog/AsyncWebServer_Teensy41/tree/main/examples/Async_WebSocketsServer) to demo how to use `Async_WebSockets`

src/AsyncJson_Teensy41.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ class AsyncCallbackJsonWebHandler: public AsyncWebHandler
405405

406406
/////////////////////////////////////////////////
407407

408-
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data,
408+
virtual void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data,
409409
size_t len, bool final) override final
410410
{
411411
}

src/AsyncWebHandlerImpl_Teensy41.h

+8
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ class AsyncCallbackWebHandler: public AsyncWebHandler
193193

194194
/////////////////////////////////////////////////
195195

196+
virtual void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) override final
197+
{
198+
if (_onUpload)
199+
_onUpload(request, filename, index, data, len, final);
200+
}
201+
202+
/////////////////////////////////////////////////
203+
196204
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index,
197205
size_t total) override final
198206
{

src/AsyncWebRequest_Teensy41.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,10 @@ void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last)
587587
if (last || _itemBufferIndex == 1460)
588588
{
589589
//check if authenticated before calling the upload
590-
if (_handler)
590+
if (_handler)
591+
{
591592
_handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false);
592-
593+
}
593594
_itemBufferIndex = 0;
594595
}
595596
}

src/AsyncWebServer_Teensy41.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class AsyncWebHandler
629629
/////////////////////////////////////////////////
630630

631631
virtual void handleRequest(AsyncWebServerRequest *request __attribute__((unused))) {}
632-
virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), const String& filename __attribute__((unused)),
632+
virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), String filename __attribute__((unused)),
633633
size_t index __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)),
634634
bool final __attribute__((unused))) {}
635635
virtual void handleBody(AsyncWebServerRequest *request __attribute__((unused)), uint8_t *data __attribute__((unused)),
@@ -697,7 +697,7 @@ class AsyncWebServerResponse
697697
* */
698698

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

703703
/////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)