• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

File Downloads from/Uploads to microSD using ESP32 webserver

Q&A Forum › Category: ESP32 › File Downloads from/Uploads to microSD using ESP32 webserver
1 Vote Up Vote Down
Stephen Rogers asked 4 years ago

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.

6 Answers
1 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

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

0 Vote Up Vote Down
Bernie answered 3 years ago

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

1 Vote Up Vote Down
Stephen Rogers answered 3 years ago

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
 
 
 

1 Vote Up Vote Down
William Lucid answered 3 years ago

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

1 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

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

0 Vote Up Vote Down
Bernie answered 2 years ago

Hi Stephen and Sara — than you for your useful references.  Best regards.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.