0

Below Arduino ESP32 code creates a list of files as URL's. I am converting WiFi client/server project to use the AsyncWebServer library. Need help extracting file name from URL and be able to detect filename to download in Async Web Server.

String str;

if (!SPIFFS.begin(true))
{
     Serial.println("An Error has occurred while mounting SPIFFS");
     return;
}

File root = SPIFFS.open("/");

File file = root.openNextFile();

while (file)
{

     if(strncmp(file.name(), "/LOG", 4) == 0)
     {
          str += "<a href=\"";
          str += file.name();
          str += "\">";
          str += file.name();
          str += "</a>";
          str += "    ";
          str += file.size();
          str += "<br>\r\n";

     }

     file = root.openNextFile();
}

client.print(str);

Attempt to code for Asyncwebserver:

serverAsync.on(filename, HTTP_GET, [](AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Ok");
response->addHeader("Content-Disposition", "attachment");
request->send(response);
});

This code produces: Download window with correct filename; however, content is only "ok."

My initial attempt was to try something with PHP. I am less than an experienced coder with PHP and with Async Web Server.

William

William Lucid
  • 23
  • 2
  • 6
  • What do you want? Execute a php-script on the ESP32? You will never be able to install a PHP-server to an ESP32! If you have a php script, you have to hard code it directly in your sketch, you can't "compile" it like a linux web server. – Adriano Oct 23 '19 at 14:41

1 Answers1

0

Solution to question provided by Pablo2048

Twenty three comments about the issue; almost at bottom, comment #21 Pablo2048 explains his approach and coding for the solution.

William

William Lucid
  • 23
  • 2
  • 6