如何使用AsyncWebServer下载SPIFFS文件?

时间:2019-10-19 10:18:31

标签: arduino spiffs

下面的Arduino ESP32代码创建一个文件列表作为URL。我正在将WiFi客户端/服务器项目转换为使用AsyncWebServer库。需要帮助从URL提取文件名,并且能够检测文件名以下载到Async Web Server中。

    2019-10-19 18:15:00,696 INFO  [AsyncFSWAL-0] wal.AbstractFSWAL: Slow sync cost: 130 ms, current pipeline: [DatanodeInfoWithStorage[10.20.69.39:9866,DS-467702ba-44df-41c3-884f-cc24c595448f,DISK], DatanodeInfoWithStorage[10.20.80.28:9866,DS-f83fcab7-1551-4bf7-97b4-2a81ce2c09b2,DISK], DatanodeInfoWithStorage[10.20.80.29:9866,DS-34ded4dc-29f2-4a8b-8805-216e4b7a98c3,DISK]]
    2019-10-19 18:15:00,696 INFO  [AsyncFSWAL-0] wal.AbstractFSWAL: Slow sync cost: 129 ms, current pipeline: [DatanodeInfoWithStorage[10.20.69.39:9866,DS-467702ba-44df-41c3-884f-cc24c595448f,DISK], DatanodeInfoWithStorage[10.20.80.28:9866,DS-f83fcab7-1551-4bf7-97b4-2a81ce2c09b2,DISK], DatanodeInfoWithStorage[10.20.80.29:9866,DS-34ded4dc-29f2-4a8b-8805-216e4b7a98c3,DISK]]
    2019-10-19 18:15:00,696 INFO  [AsyncFSWAL-0] wal.AbstractFSWAL: Slow sync cost: 129 ms, current pipeline: [DatanodeInfoWithStorage[10.20.69.39:9866,DS-467702ba-44df-41c3-884f-cc24c595448f,DISK], DatanodeInfoWithStorage[10.20.80.28:9866,DS-f83fcab7-1551-4bf7-97b4-2a81ce2c09b2,DISK], DatanodeInfoWithStorage[10.20.80.29:9866,DS-34ded4dc-29f2-4a8b-8805-216e4b7a98c3,DISK]]
    2019-10-19 18:15:00,696 INFO  [AsyncFSWAL-0] wal.AbstractFSWAL: Slow sync cost: 129 ms, current pipeline: [DatanodeInfoWithStorage[10.20.69.39:9866,DS-467702ba-44df-41c3-884f-cc24c595448f,DISK], DatanodeInfoWithStorage[10.20.80.28:9866,DS-f83fcab7-1551-4bf7-97b4-2a81ce2c09b2,DISK], DatanodeInfoWithStorage[10.20.80.29:9866,DS-34ded4dc-29f2-4a8b-8805-216e4b7a98c3,DISK]]

尝试为Asyncwebserver编码:

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);

此代码产生:具有正确文件名的下载窗口;但是,内容只是“确定”。

我最初的尝试是尝试使用PHP。我还不具备PHP和Async Web Server的经验。

威廉

1 个答案:

答案 0 :(得分:0)

Solution to question provided by Pablo2048

关于此问题的23条评论;几乎在最后,注释#21 Pablo2048解释了他的方法和解决方案的编码。

威廉