DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
upload_service.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file upload_service.h
6 * @brief Streaming file upload to an Arduino FS (DETWS_ENABLE_UPLOAD).
7 *
8 * Registers a POST route whose request body is streamed straight into a file on
9 * a filesystem (LittleFS / SPIFFS / SD) in FILE_CHUNK_SIZE pieces - the upload
10 * never has to fit in RAM. Reuses the parser's streaming-body hook (the same
11 * mechanism OTA uses), so it is zero-heap and bounded.
12 *
13 * One upload at a time (the device runs a single loop task). Only one streaming
14 * sink can be installed, so DETWS_ENABLE_UPLOAD and DETWS_ENABLE_OTA share the
15 * parser hook - register whichever you need (not both on the same build).
16 */
17
18#ifndef DETERMINISTICESPASYNCWEBSERVER_UPLOAD_SERVICE_H
19#define DETERMINISTICESPASYNCWEBSERVER_UPLOAD_SERVICE_H
20
21#include "ServerConfig.h"
22
23#if DETWS_ENABLE_UPLOAD
24
25#include <FS.h>
26#include <stddef.h>
27
28class DetWebServer;
29
30/**
31 * @brief Register a streaming-upload endpoint.
32 *
33 * A `POST @p path` request streams its body into @p dest_path on @p fs (the file
34 * is truncated/created). The route handler replies `200 OK <n> bytes` on success
35 * or 500 on a write failure.
36 *
37 * @param server the web server.
38 * @param path the upload URL (e.g. "/upload").
39 * @param fs target filesystem (LittleFS / SPIFFS / SD).
40 * @param dest_path destination file path (e.g. "/uploads/data.bin").
41 */
42void detws_upload_begin(DetWebServer &server, const char *path, fs::FS &fs, const char *dest_path);
43
44/** @brief Bytes written by the most recent upload (for handlers / tests). */
45size_t detws_upload_last_size();
46
47#endif // DETWS_ENABLE_UPLOAD
48
49#endif // DETERMINISTICESPASYNCWEBSERVER_UPLOAD_SERVICE_H
User-facing configuration for DeterministicESPAsyncWebServer.
Single-port HTTP server with deterministic, zero-allocation execution.
Definition dwserver.h:348