Is there a RN course or tutorial on building a file download/upload utlity? I thought this would be part of the course on ESP32 webservers but I haven’t seen it. The project is a datalogger that logs readings to microSD.
Hi Stephen.
No, we don’t cover that subject in our ebooks.
I found this video that might help: https://youtu.be/6XR6BXbc0aI
Regards,
Sara
Hi Sara, I need to transfer small files between the ESP32 running ESPAsyncWebServer and the client.
The link above uses the library ESP32WebServer.h, but I want to stay with ESPAsyncWebServer.
Can the above code be adapted to the Async library?
Do you have examples of code for ESPAsyncWebServer to upload and download files?
Thanks a lot,
Bernie
Hi Bernie,
I have cracked the nut on the downloading part and it is working well.
Here is an article that helped me get there: https://techtutorialsx.com/2019/03/29/esp32-arduino-serving-file-as-attachment/
I haven’t needed ability to upload a file yet but I’m sure the technique is similar, in reverse. For downloading, you use the same approach as in any webserver, which is that you employ HTTP_GET, and instead of specifying the file for rendering by the browser, you specify to just send the file as an attachment. This is well explained in the article and in other articles/documentation that explain or demonstrate how to use routing.. Here is code (in setup) that I wrote for my application that shows the routing for 3 files I’m serving as attachments:::
//*****
//***** Load Webserver Routing here
//*****
// Route for root / web page
server.on(“/”, HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, “/index.html”, “text/html”, false, processor);
});
server.serveStatic(“/”, SPIFFS, “/”);
// Route to Download Data log
server.on(“/downdata”, HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SD, “/DATA.CSV”, “text/plain”, true, processor);
});
// Route to Download Status log
server.on(“/downstatus”, HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SD, “/STATUS.CSV”, “text/plain”, true, processor);
});
// Route to Download Configuration JSON file
server.on(“/downstatus”, HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, “/CONFIG.JSON”, “text/plain”, true, processor);
});
// Start server
server.begin();
} //***** End of Setup()
In the request->send() call, the 3rd parameter “true” specifies not to have the browser interpret the file i.e. send it as an attachment. This will trigger the browser’s built in file I/O dialog and ask you where to download the file to.
Good luck!
Stephen Rogers
Hi Stephen,
Asyncwebserver upload file example Example is for SPIFFS.
Asyncwebserver project –useful functions? I have had allot of help with this project over the years in development. String processor2 function; generates a list of filenames as URL links, Once a link is clicked the onNotFound function takes URL link and converts it back to a filename. Other functions in project may be use in yours and others projects.
William
Hi Bernie.
Unfortunately, we don’t have any tutorials about that.
I hope the previous answers help you with your project.
Aditionally, the AsyncWebserver library has several examples and code snippets that might help. Here’s the documentation: https://github.com/me-no-dev/ESPAsyncWebServer
Regards,
Sara