diff --git a/esphome/components/ota_base/ota_backend_arduino_esp32.cpp b/esphome/components/ota_base/ota_backend_arduino_esp32.cpp index 34ba3ae6ff..b89c61472a 100644 --- a/esphome/components/ota_base/ota_backend_arduino_esp32.cpp +++ b/esphome/components/ota_base/ota_backend_arduino_esp32.cpp @@ -15,6 +15,11 @@ static const char *const TAG = "ota.arduino_esp32"; std::unique_ptr make_ota_backend() { return make_unique(); } OTAResponseTypes ArduinoESP32OTABackend::begin(size_t image_size) { + // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA + // where the exact firmware size is unknown due to multipart encoding + if (image_size == 0) { + image_size = UPDATE_SIZE_UNKNOWN; + } bool ret = Update.begin(image_size, U_FLASH); if (ret) { return OTA_RESPONSE_OK; diff --git a/esphome/components/ota_base/ota_backend_arduino_libretiny.cpp b/esphome/components/ota_base/ota_backend_arduino_libretiny.cpp index 12d4b677a3..052a9faed9 100644 --- a/esphome/components/ota_base/ota_backend_arduino_libretiny.cpp +++ b/esphome/components/ota_base/ota_backend_arduino_libretiny.cpp @@ -15,6 +15,11 @@ static const char *const TAG = "ota.arduino_libretiny"; std::unique_ptr make_ota_backend() { return make_unique(); } OTAResponseTypes ArduinoLibreTinyOTABackend::begin(size_t image_size) { + // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA + // where the exact firmware size is unknown due to multipart encoding + if (image_size == 0) { + image_size = UPDATE_SIZE_UNKNOWN; + } bool ret = Update.begin(image_size, U_FLASH); if (ret) { return OTA_RESPONSE_OK; diff --git a/esphome/components/ota_base/ota_backend_arduino_rp2040.cpp b/esphome/components/ota_base/ota_backend_arduino_rp2040.cpp index 7276381919..bcb87f3547 100644 --- a/esphome/components/ota_base/ota_backend_arduino_rp2040.cpp +++ b/esphome/components/ota_base/ota_backend_arduino_rp2040.cpp @@ -17,6 +17,11 @@ static const char *const TAG = "ota.arduino_rp2040"; std::unique_ptr make_ota_backend() { return make_unique(); } OTAResponseTypes ArduinoRP2040OTABackend::begin(size_t image_size) { + // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA + // where the exact firmware size is unknown due to multipart encoding + if (image_size == 0) { + image_size = UPDATE_SIZE_UNKNOWN; + } bool ret = Update.begin(image_size, U_FLASH); if (ret) { rp2040::preferences_prevent_write(true);