ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
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 (PC_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 PC_ENABLE_UPLOAD and PC_ENABLE_OTA share the
15 * parser hook - register whichever you need (not both on the same build).
16 */
17
18#ifndef PROTOCORE_UPLOAD_SERVICE_H
19#define PROTOCORE_UPLOAD_SERVICE_H
20
21#include "protocore_config.h"
22
23#if PC_ENABLE_UPLOAD
24
25#include <FS.h>
26#include <stddef.h>
27
28class PC;
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 pc_upload_begin(PC &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 pc_upload_last_size();
46
47#endif // PC_ENABLE_UPLOAD
48
49#endif // PROTOCORE_UPLOAD_SERVICE_H
Single-port HTTP server with deterministic, zero-allocation execution.
Definition protocore.h:348
User-facing configuration for ProtoCore.