Skip to content

The server doesn't complete my file uploads that are larger than 2MB #305

@Shimoe-Koharu16

Description

@Shimoe-Koharu16

Platform

ESP32

IDE / Tooling

Arduino (IDE/CLI)

What happened?

Whenever I try to upload a file that's larger than 2MB, it doesn't continue and leaves an incomplete file data (corrupt file in other words). To be specific, I was trying to upload a file that's 28MB+ on size (ZIP file), but when I'm about to extract the file on my PC or phone (after downloading the file/ZIP folder), it doesn't open with any file explorers I use (Nautilus and Files). The Serial output says that the upload was a success but it doesn't actually finished writing on the SD card. I already added .flush() to rule out RAM limitations (but the average RAM use while upload is ~210kB based on the dashboard on Blynk that I set up on my ESP32 as an RTOS task). But, it still does produce the same bug or problem

Stack Trace

------------------------------------------
  Compile Date/Time : Oct  7 2025 18:40:59
  Compile Host OS   : linux
  ESP-IDF Version   : v5.5.1-1-g129cd0d247
  Arduino Version   : 3.3.0
------------------------------------------
Board Info:
------------------------------------------
  Arduino Board     : ESP32_DEV
  Arduino Variant   : esp32
  Arduino FQBN      : esp32:esp32:esp32:UploadSpeed=921600,CPUFreq=240,FlashFreq=80,FlashMode=qio,FlashSize=4M,PartitionScheme=default,DebugLevel=debug,PSRAM=disabled,LoopCore=1,EventsCore=1,EraseFlash=none,JTAGAdapter=default,ZigbeeMode=default
============ Before Setup End ============
Server Initialized
=========== After Setup Start ============
[  7369][D][NetworkManager.cpp:83] hostByName(): Clearing DNS cache
INTERNAL Memory Info:
------------------------------------------
  Total Size        :   317784 B ( 310.3 KB)
  Free Bytes        :   155816 B ( 152.2 KB)
  Allocated Bytes   :   150304 B ( 146.8 KB)
  Minimum Free Bytes:   155772 B ( 152.1 KB)
  Largest Free Block:    94196 B (  92.0 KB)
------------------------------------------
GPIO Info:
------------------------------------------
  GPIO : BUS_TYPE[bus/unit][chan]
  --------------------------------------  
     1 : UART_TX[0]
     2 : GPIO
     3 : UART_RX[0]
     5 : SD_SS
    17 : GPIO
    18 : SPI_MASTER_SCK[3]
    19 : SPI_MASTER_MISO[3]
    23 : SPI_MASTER_MOSI[3]
============ After Setup End =============
[  7486][D][NetworkManager.cpp:127] hostByName(): DNS found IPv4 128.199.144.129
Upload Start: てるくず.zip
Upload Success: てるくず.zip

Minimal Reproductible Example (MRE)

Here's the upload endpoint for my website to send the files to
  server.on(
    "/upload", HTTP_POST, [](AsyncWebServerRequest *request) {
      request->send(204);
    },
    handleUpload);

And here's my upload handler 

`void handleUpload(AsyncWebServerRequest *request, const String &filename,
                  size_t index, uint8_t *data, size_t len, bool final) {

  if (index == 0) {
    if (!enable_upload) {
      events.send("Upload disabled from the the dashboard", "toast", millis());
      return;
    }
    Serial.printf("Upload Start: %s\n", filename.c_str());
    fn = filename;
    String path = "/uploads/" + filename;
    uploadFile = SD.open(path, FILE_WRITE);
    if (!uploadFile) {
      Serial.println("Failed to open file for writing");
      return;
    }
  }
  if (!enable_upload) {
    events.send("Upload disabled from the the dashboard", "toast", millis());
    return;
  }
  if (uploadFile) {
    if (len > 0)
      uploadFile.write(data, len);
      uploadFile.flush();
      digitalWrite(2, HIGH);
    if (final) {
      uploadFile.close();
      Serial.printf("Upload Success: %s\n", filename.c_str());
    }
    digitalWrite(2, LOW);
  }
}`

I confirm that:

  • I have read the documentation.
  • I have searched for similar discussions.
  • I have searched for similar issues.
  • I have looked at the examples.
  • I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions