AsyncWebServer_Teensy41 for QNEthernet

Hi,
Is there anybody who managed to upload a file from a web browser to a teensy 4.1 using this asyncWebServer library?
In the cpp file, there is:
AsyncCallbackWebHandler& AsyncWebServer::eek:n(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload)
I guess this is what we have to go through. But can't find a way to implement in my webserver initialization...
Any idea?
 
when declaring:
Code:
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {},[](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final) {}

I get an error: no matching function for call to 'AsyncWebServer::eek:n(const char [8], WebRequestMethod, WebServer::init()::<lambda(AsyncWebServerRequest*)>, WebServer::init()::<lambda(AsyncWebServerRequest*, String, size_t, uint8_t*, size_t, bool)>)'
 
Little progress:
There's no String filename in the ArUploadHandlerFunction type.
So the correct syntax is:
Code:
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest *request) {},[](AsyncWebServerRequest *request, size_t index, uint8_t *data, size_t len, bool final) {});
But I can't get the data. when I upload a file from a web browser, the onRequest function is triggered (I can get the filename and the size), but not the onUpload function
my code:
Code:
server.on("/upload", HTTP_POST, [&](AsyncWebServerRequest *request) {
            AsyncWebParameter* p = request->getParam(0);
            Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size());
    },[&](AsyncWebServerRequest *request, size_t index, uint8_t *data, size_t len, bool final) {
            Serial.println(len);
            return;
});

no error on the website side, validated with wireshark...
 
Well, looks like a bug in the library. But the library is marked as archive so you can't send an issue...

For those who want to try:
Code:
server.on("/upload", HTTP_GET, [](AsyncWebServerRequest * request) {
    String html = "<body><div><form method='POST' enctype='multipart/form-data' action='/upload'><input type='file' name='dummy'><button type='submit'>Send</button></form></div></body>";
    request->send(200, "text/html", html);
    });

server.on("/upload", HTTP_POST, [&](AsyncWebServerRequest *request) {
            AsyncWebParameter* p = request->getParam(0);
            Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size()); //<= I can see this
    },[&](AsyncWebServerRequest *request, size_t index, uint8_t *data, size_t len, bool final) {
            Serial.println(len);  //<= never called
            return;
    });
 
REFERENCE:
https://github.com/khoih-prog/WebSo...NEthernet/Teensy41_Client/Teensy41_Client.ino

Hello khoih-prog,

My question should probably be posted elsewhere but this is the thread closest to my issue.

Is it possible use the above mentionned sketch if I already have an spi client on Teensy 4.1 with ethernet kit ?

I noticed SPI.H is being used in your sketch.
In QNEthernet I did not find any example using SPI.

Are there limitations on using SPI with this sketch? If so , where can I find them ?

Thank you in advance,
Leo
 
Well, looks like a bug in the library. But the library is marked as archive so you can't send an issue...

For those who want to try:
Code:
server.on("/upload", HTTP_GET, [](AsyncWebServerRequest * request) {
    String html = "<body><div><form method='POST' enctype='multipart/form-data' action='/upload'><input type='file' name='dummy'><button type='submit'>Send</button></form></div></body>";
    request->send(200, "text/html", html);
    });

server.on("/upload", HTTP_POST, [&](AsyncWebServerRequest *request) {
            AsyncWebParameter* p = request->getParam(0);
            Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size()); //<= I can see this
    },[&](AsyncWebServerRequest *request, size_t index, uint8_t *data, size_t len, bool final) {
            Serial.println(len);  //<= never called
            return;
    });

@Shuptuu Hey I know this is a little old, but I was able to get this working.

Add this to AsyncWebHandlierImpl_Teensy41.h around line 196
Code:
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final {
      if(_onUpload)
        _onUpload(request, filename, index, data, len, final);
    }

    /////////////////////////////////////////////////

Uncomment the const String& filename parameter in AsyncWebServer_Teensy41.hpp around line 700
Code:
typedef std::function<void(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final)> ArUploadHandlerFunction;

Your code was able to spark something in my brain to fix an issue I've had for a long time so I wanted to return the favor.

Special thanks to khoih-prog for doing a whole bunch of work on this project!
 
Hi, I'm a little late to the party.
Has anyone had a bug where the HTTP Response Header gets not send correctly? Instead of
Code:
HTTP/1.1 200 OK
I receive something like
Code:
(0xf8 cc 00 20 f8 cc 00) 200 OK
This happens somethings when I hit the Server with two or more requests simultaneously. Interestingly only the "HTTP/1.1" gets not send correctly. "200 OK" and the payload are always intact.

For context:
My teensy is connected to 4 Serial devices and I use the Webserver provide access to them over a local network. I have a Raspberry Pi that is requesting data from the Webserver in multiple threads and therefore the request are sometimes simultaneously.

Workaround:
As workaround I will catch the error and look if at least the "200 OK" is in the header and continue as normal.
 
Back
Top