user54202: I'm following the examples for ESP32:
  AsyncWebServer _server(80);

  _server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request->send(SPIFFS, "/index.html", String(), false);
  });

  _server.on("/css/index.css", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/css/index.css", "text/css");
  });

  _server.onNotFound([](AsyncWebServerRequest *request){
    request->send(404);
  });

_server.begin();

With this approach I have to know in advance each file I store in the SPIFFS and add a handler for each one.
Is there a more elegant way to automatically serve any file that exists in the flash?

user42015: You can tell the webserver to serve the static content from a specific folder:
server.serveStatic("/", SPIFFS, "/").setDefaultFile("index.html");

In this case it serves on the root URL the content from the SPIFFS root. So if I place a file called image.jpg in the SPIFFS root it will be served at /image.jpg.
For more information you can look at the corresponding section of the libraries Readme file.

54202: <p>I'm following the examples for ESP32:</p>
<pre><code>  AsyncWebServer _server(80);

  _server.on(&quot;/&quot;, HTTP_GET, [](AsyncWebServerRequest *request)
  {
    request-&gt;send(SPIFFS, &quot;/index.html&quot;, String(), false);
  });

  _server.on(&quot;/css/index.css&quot;, HTTP_GET, [](AsyncWebServerRequest *request){
    request-&gt;send(SPIFFS, &quot;/css/index.css&quot;, &quot;text/css&quot;);
  });

  _server.onNotFound([](AsyncWebServerRequest *request){
    request-&gt;send(404);
  });

_server.begin();
</code></pre>
<p>With this approach I have to know in advance each file I store in the <code>SPIFFS</code> and add a handler for each one.</p>
<p>Is there a more elegant way to automatically serve any file that exists in the flash?</p>
 42015: <p>You can tell the webserver to serve the static content from a specific folder:</p>
<pre><code>server.serveStatic(&quot;/&quot;, SPIFFS, &quot;/&quot;).setDefaultFile(&quot;index.html&quot;);
</code></pre>
<p>In this case it serves on the root URL the content from the SPIFFS root. So if I place a file called <code>image.jpg</code> in the SPIFFS root it will be served at <code>/image.jpg</code>.
For more information you can look at <a href="https://github.com/me-no-dev/ESPAsyncWebServer#serving-static-files" rel="nofollow noreferrer">the corresponding section of the libraries Readme file</a>.</p>
