G6EJD / G6EJD-ESP-File-Server

An ESP32 system that can perform a Directory, Upload, Download, Delete, Rename and Stream Files in SPIFFS
Other
64 stars 25 forks source link

Downloading error over 5.6 KB data and Streaming data upto 5.6 KB #1

Closed OmnixOne closed 1 year ago

OmnixOne commented 2 years ago

Hello everyone,

I want to download and stream files of spiffs using a web server but I'm struggling when it comes to downloading and streaming files over 5.6 KB. While using this library here I get the size of maxLen and it is 5.6 KB, I think due to the maxLen size I can't download files over 5.6 KB, and on-stream it streams only 5.6 KB of data. So how do I download and stream data over 5.6 KB? and how can I change maxLen size? Device: M5Core 2

G6EJD commented 2 years ago

What ESP32 compiler are you using, if not 1.0.6, try that. Or change to a chunked response, see server readme

OmnixOne commented 2 years ago

I am using ESP32 1.0.6 version.

On Mon, Jun 13, 2022 at 12:36 PM G6EJD @.***> wrote:

What ESP32 compiler are you using, if not 1.0.6, try that. Or change to a chunked response, see server readme

— Reply to this email directly, view it on GitHub https://github.com/G6EJD/G6EJD-ESP-File-Server/issues/1#issuecomment-1153551628, or unsubscribe https://github.com/notifications/unsubscribe-auth/AW5JJPHJYTZIM326JNDVPV3VO3MW5ANCNFSM5YTCN2SQ . You are receiving this because you authored the thread.Message ID: @.***>

OmnixOne commented 2 years ago

And I have tried all chunked responses, but the bug still continues and it's downloading and streaming data up to 5KB only.

On Mon, Jun 13, 2022 at 4:31 PM suraj singh @.***> wrote:

I am using ESP32 1.0.6 version.

On Mon, Jun 13, 2022 at 12:36 PM G6EJD @.***> wrote:

What ESP32 compiler are you using, if not 1.0.6, try that. Or change to a chunked response, see server readme

— Reply to this email directly, view it on GitHub https://github.com/G6EJD/G6EJD-ESP-File-Server/issues/1#issuecomment-1153551628, or unsubscribe https://github.com/notifications/unsubscribe-auth/AW5JJPHJYTZIM326JNDVPV3VO3MW5ANCNFSM5YTCN2SQ . You are receiving this because you authored the thread.Message ID: @.***>

G6EJD commented 2 years ago

Which board/cpu are you using, how much spare RAM is available? I think is is most likely a compiler setting or board selection issue as it was all working and the library has not been updated in over 3-years, so it must be something other than the asynchronous web-server

OmnixOne commented 2 years ago

Full Board Description Microcontroller: Tensilica 32-bit Single-/Dual-core CPU Xtensa LX6

ESP32 BoardLink

Arduino IDE 1.8.19 Compiler Xtensa GNU compiler collection (GCC) Version:  Tensilica 32-bit Single-/Dual-core CPU Xtensa LX6 ESPAsyncWebServer library branch == f71e3d427b5be9791a8a2c93cf8079792c3a9a26 (We are using this latest master branch) Log File of uploading, downloading and streaming:

/home/omnixone05/Music/ESPAsynch_Server_v1/ESPAsynch_Server_v1.ino
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 0 - WIFI_READY
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 2 - STA_START
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 4 - STA_CONNECTED
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 7 - STA_GOT_IP
[D][WiFiGeneric.cpp:419] _eventCallback(): STA IP: 192.168.1.106, MASK: 255.255.255.0, GW: 192.168.1.1
IP Address: 192.168.1.106
System started successfully...
[D][WiFiGeneric.cpp:374] _eventCallback(): Event: 1 - SCAN_DONE
Uploading file...
Transferred : 1460 Bytes
Transferred : 1268 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1436 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1434 Bytes
Transferred : 1 Bytes
Transferred : 1 Bytes
Transferred : 1436 Bytes
Transferred : 1434 Bytes
Transferred : 1 Bytes
Transferred : 1 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1460 Bytes
Transferred : 1412 Bytes
Transferred : 1436 Bytes
Transferred : 1436 Bytes
Transferred : 1428 Bytes
File Directory...
Streaming file...
Stream handler started...
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4
Downloading file...
Download handler started...
[W][AsyncTCP.cpp:969] _poll(): rx timeout 4

Here I am attaching the screenshot of arduino setting. Screenshot from 2022-06-14 12-05-54 And please tell how we can increase the size of maxLen ?? because the size of maxLen is 5.6 KB and it downloading and straming upto 5.6 KB only.

G6EJD commented 2 years ago

Sorry. That’s a query for the library author at Espressif, not me.

OmnixOne commented 2 years ago

Have you tried to download and stream a File above 5.6 KB?

G6EJD commented 2 years ago

Not since I published the code, I may try it it again when I can find time. I'll let you know when I do. It all worked up to 1MB files, that's why I included the test files.

OmnixOne commented 2 years ago

We will wait for you.

elektroboard commented 1 year ago

me too

G6EJD commented 1 year ago

If you use an earlier compiler version 1.6 for the ESP32 then it will work

franzbischoff commented 1 year ago

This solves the problem on download requests:

    if (request->url().startsWith("/downloadhandler"))
    {
      Serial.println("Download handler started...");
      MessageLine = "";
      File file = FS.open(filename, "r");
      String contentType = getContentType("download");
      AsyncWebServerResponse *response = request->beginResponse(contentType, file.size(), [file](uint8_t *buffer, size_t maxLen, size_t total) mutable ->  size_t
                                                                { return file.read(buffer, maxLen); });
      response->addHeader("Server", "ESP Async Web Server");
      request->send(response);
    }
elektroboard commented 1 year ago

This solves the problem on download requests:

    if (request->url().startsWith("/downloadhandler"))
    {
      Serial.println("Download handler started...");
      MessageLine = "";
      File file = FS.open(filename, "r");
      String contentType = getContentType("download");
      AsyncWebServerResponse *response = request->beginResponse(contentType, file.size(), [file](uint8_t *buffer, size_t maxLen, size_t total) mutable ->  size_t
                                                                { return file.read(buffer, maxLen); });
      response->addHeader("Server", "ESP Async Web Server");
      request->send(response);
    }

Thanks. İ will try it

wsndy commented 1 year ago

This solves the problem on download requests:

    if (request->url().startsWith("/downloadhandler"))
    {
      Serial.println("Download handler started...");
      MessageLine = "";
      File file = FS.open(filename, "r");
      String contentType = getContentType("download");
      AsyncWebServerResponse *response = request->beginResponse(contentType, file.size(), [file](uint8_t *buffer, size_t maxLen, size_t total) mutable ->  size_t
                                                                { return file.read(buffer, maxLen); });
      response->addHeader("Server", "ESP Async Web Server");
      request->send(response);
    }

Thanks. İ will try it

Hi, is your problem solved? I had the same problem, still only able to download 5.6k with the new code. Arduino IDE 1.8.19 ESP32 compiler version 2.0.5 board: DOIT ESP32 DEVKIT V1

franzbischoff commented 1 year ago

It solved it for me. Maybe you should review the current version of this library and see what works for you: https://github.com/me-no-dev/ESPAsyncWebServer BR

ELECTRONIC-FM-SYSTEMS commented 1 year ago

Saludos!!! Quiero descargar los archivos subidos o cargados a mi ESP32 S3, pero no deja descargar a mas de 5.6Kb, utilizando arduino 1.8.19. Han probado descargar los archivos a mas de 5.6Kb, tambien he utilizado el ESP32 WROOM y tampoco el mismo problema de descarga ya he actualizado los archivos y nada.

G6EJD commented 1 year ago

He actualizado el código para corregir este problema. es realmente un problema del compilador, no un problema de código.

ayaghini commented 1 year ago

Dear David,

First, thanks for your time here.

Another user with the same problem here.

I am using ESP32-S3, also I am trying to use the SD instead of the SPIFF. I can successfully download files up to 5.6k but no luck with the greater ones. This is the change I made to make it compatible with SD:

if (request->url().startsWith("/downloadhandler")) {
      Serial.println("Download handler started...");
      MessageLine = "";
      File file = SD.open(filename);
      String contentType = getContentType("download");
      AsyncWebServerResponse* response = request->beginResponse(contentType, file.size(), [file](uint8_t *buffer, size_t maxLen, size_t total) mutable -> size_t {
        return file.read(buffer, maxLen);
      });
      response->addHeader("Server", "ESP Async Web Server");
      request->send(response);
      downloadtime = millis() - start;
      downloadsize = GetFileSize(filename);
      request->redirect("/dir");
    }

I know that this is perhaps not your priority, but any help that puts me in the right direction would be appreciated.

Thanks

PS: I am using wifi in AP mode.

I tried the solution proposed earlier, removing those lines will cause the board to crash constantly.

ayaghini commented 1 year ago

This solves the problem on download requests:

    if (request->url().startsWith("/downloadhandler"))
    {
      Serial.println("Download handler started...");
      MessageLine = "";
      File file = FS.open(filename, "r");
      String contentType = getContentType("download");
      AsyncWebServerResponse *response = request->beginResponse(contentType, file.size(), [file](uint8_t *buffer, size_t maxLen, size_t total) mutable ->  size_t
                                                                { return file.read(buffer, maxLen); });
      response->addHeader("Server", "ESP Async Web Server");
      request->send(response);
    }

This at the end solved my problem. For anyone else, my issue was my ESP board (Adafruit ESP32-S3) that crashed when I did upload the sketch.

Thanks Dave for this great work!

G6EJD commented 1 year ago

Thank you I have updated the code accordingly.