Multipart Upload Architecture#
CloudPaste supports two distinct multipart upload strategies, determined by the target storage backend :
| Mode | How it works | Backends |
|---|---|---|
per_part_url | Backend returns a presigned URL per chunk; browser uploads directly to the provider โ Workers never touch the data. | S3, R2, HuggingFace |
single_session | Backend returns one session URL; browser PUTs each chunk to PUT /api/fs/multipart/upload-chunk, which proxies it to the upstream. | Telegram, Google Drive, OneDrive |
The route entry point is backend/src/routes/fs/multipart.js.
Telegram Driver#
Key files: TelegramStorageDriver.js ยท TelegramMultipartOperations.js
Part size: default 15 MB; configurable via part_size_mb; enforced range is [5 MB, 100 MB] .
Critical constraint โ full in-memory buffering: Every chunk is buffered entirely into Worker memory. _toBlob() reads the incoming ReadableStream into a Uint8Array, wraps it in a Blob, and sends it as multipart/form-data to the Telegram Bot API. Streaming is impossible โ Telegram's API requires a complete payload .
Idempotency: proxyFrontendMultipartChunk marks each part as uploading in upload_parts before sending, and polls up to ~12 s if a concurrent request is already handling the same byte range .
Completion: completeFrontendMultipartUpload verifies all parts are present, constructs a telegram_manifest_v1 JSON (list of file_id/message_id per part), and writes it to vfs_nodes.content_ref .
Google Drive Driver#
Key files: GoogleDriveUploadOperations.js ยท GoogleDriveStorageDriver.js
Part size: default 5 MB; must be a multiple of 256 KB per Google's resumable upload API .
Streaming-safe: Unlike Telegram, proxyFrontendMultipartChunk passes the request body directly as the fetch() body to the Google Drive resumable session URL โ no in-memory buffering . Google Drive is not affected by the Workers 128 MB memory limit.
Session model: initializeFrontendMultipartUpload opens a uploadType=resumable session with Google Drive and stores the returned location URL as provider_upload_url in upload_sessions .
Cloudflare Workers Memory Limit#
Cloudflare Workers has a 128 MB memory cap. For single_session Telegram uploads, each chunk is fully materialized in memory โ twice: once as the raw stream buffer and once as the Blob for FormData construction .
Approximate peak memory for Telegram:
chunk_size ร concurrency ร 2 + Workers runtime overhead
At 20 MB chunks ร 3 concurrent uploads โ ~120โ130 MB, which triggers Worker exceeded memory limit (HTTP 503) on PUT /api/fs/multipart/upload-chunk .
Upload stalls at low throughput (e.g., ~1 MB before freezing) can also occur in poor-network conditions where chunks time out before completing the proxy round-trip .
Mitigations:
| Option | Notes |
|---|---|
| Reduce Telegram part size to 5 MB (minimum) + concurrency to 1 | Keeps peak memory ~10โ15 MB |
| Docker deployment | No Workers memory cap; Telegram uploads work without restriction |
| Switch to S3/R2 | Uses per_part_url; bypasses Workers entirely |
Database Tables#
upload_sessionsโ one row per upload session; tracksstatus,part_size,total_parts,bytes_uploaded,provider_upload_url.upload_partsโ one row per chunk; trackspart_no,byte_start,byte_end,provider_part_id,status(uploading/uploaded/error). Rows are deleted aftercompleteFrontendMultipartUpload.