Multipart Chunked Uploads
FynnCloud streams large uploads through a resilient 3-step multipart protocol (MultipartUploadService) that works identically across Local Disk and S3-Compatible Object Storage while enforcing strict per-user quotas, live revocation checks, and atomic file versioning.
Protocol Constants & Safety Bounds
Section titled “Protocol Constants & Safety Bounds”| Rule | Value |
|---|---|
| Maximum chunk size | STORAGE_MAX_CHUNK_SIZE (default 100mb) |
| Minimum S3 non-final chunk size | 5 MiB (S3 protocol requirement) |
| Maximum parts per upload | maxParts = 10_000 (1-indexed: 1..10000) |
| Cumulative byte cap slack | 5% or 1 MiB above claimed size (enforced atomically via Redis Lua on upload:parts:{sessionID}) |
| Session & chunk TTL | 24 hours (abandoned sessions cleaned hourly by UploadCleanupJob) |
| Local chunk storage path | {STORAGE_PATH}/{userID}/_system/chunks/{fileID}/{uploadID}/part_{N} |
Step 1: Initialize Upload (POST /api/files/upload/init)
Section titled “Step 1: Initialize Upload (POST /api/files/upload/init)”{ "name": "archive.tar.gz", "size": 524288000, "parentId": "<optional-folder-uuid>", "mimeType": "application/gzip", "overwriteFileId": "<optional-existing-file-uuid>"}What init Performs
Section titled “What init Performs”- Authorization & Quota Reservation: Verifies write permission to
parentId(oroverwriteFileId/ publicfile_droporcollaborativeshare) and calculates reserved bytes:- New file or overwrite when
storageMaxFileVersions > 0 && previousSize > 0(versioning will snapshot the previous blob): reserves the fullsize. - Overwrite when versioning is disabled (
storageMaxFileVersions == 0): reserves onlymax(0, size - previousSize).
- New file or overwrite when
- Storage Preparation:
- S3: Initiates an S3 Multipart Upload (
CreateMultipartUpload) and stores the S3uploadId. - Local Disk: Allocates staging directory
{STORAGE_PATH}/{userID}/_system/chunks/{fileID}/{uploadID}/.
- S3: Initiates an S3 Multipart Upload (
- Signed Session Token: Returns
{ uploadId, uploadToken, chunkSize, maxParts }whereuploadTokenis a signedUploadSessionTokenJWT bound to the session, user/share, claimed size, and backinggrantID/shareLinkID.
Step 2: Stream Chunks (PUT /api/files/upload/:uploadId/part/:partNumber)
Section titled “Step 2: Stream Chunks (PUT /api/files/upload/:uploadId/part/:partNumber)”Upload parts concurrently (the web client sends up to 3 parallel chunks per file, 3 concurrent files, with 3 retries per chunk):
PUT /api/files/upload/<uploadId>/part/1Authorization: Bearer <uploadToken>Content-Type: application/octet-stream
<raw binary chunk bytes>Per-Part Guards Enforced on Every Chunk
Section titled “Per-Part Guards Enforced on Every Chunk”- Live Revocation Check: Even though
uploadTokenis a signed JWT, every part checks whether the backing OAuth grant (grant:revoked:{grantID}) or public share link has been revoked—aborting immediately if access was removed mid-upload. - Range & Cap Validation: Validates
1 <= partNumber <= 10_000and per-part byte limit (STORAGE_MAX_CHUNK_SIZE). - Redis Lua Cumulative Byte Guard (
upload:parts:{sessionID}, 24h TTL): Atomically tracks per-part sizes and rejects any chunk that would push the cumulative uploaded bytes beyondclaimedSize + max(claimedSize * 5%, 1 MiB)(preventing a client from claiming a 1 MB upload atinitto bypass quota and then streaming 10 GB of parts). - Streaming Storage Write:
- S3: Streams directly into
UploadPart(STORAGE_S3_TIMEOUT, default900s) and returns{ partNumber, etag }. - Local Disk: Writes
{STORAGE_PATH}/{userID}/_system/chunks/{fileID}/{uploadID}/part_{partNumber}and returns{ partNumber, etag }.
- S3: Streams directly into
Step 3: Complete Upload (POST /api/files/upload/:uploadId/complete)
Section titled “Step 3: Complete Upload (POST /api/files/upload/:uploadId/complete)”{ "parts": [ { "partNumber": 1, "etag": "\"abc123...\"" }, { "partNumber": 2, "etag": "\"def456...\"" } ]}Zero-Byte File Completion
Section titled “Zero-Byte File Completion”To upload a 0-byte file (e.g., an empty .txt or .keep file), call init with "size": 0 and call complete immediately with "parts": []—no PUT .../part/N requests are required.
Atomic Commit & Post-Processing
Section titled “Atomic Commit & Post-Processing”- Versioning Snapshot: If overwriting an existing non-empty file and
storageMaxFileVersions > 0, snapshots the existing blob intofile_versionsand prunes versions above the configured cap. - Assembly:
- S3: Calls
CompleteMultipartUpload. - Local Disk: Concatenates
part_1..part_Nsequentially into{STORAGE_PATH}/{userID}/{fileID}, computes the SHA-256 hash, and cleans up_system/chunks/{fileID}/{uploadID}/.
- S3: Calls
- Database, Quota & Events: Commits
FileMetadata, releases the Redisquota:pending:{userID}while incrementingusers.current_storage_usage, records aFileActivity+SyncLogentry, schedules a debounced File Provider PushKit wakeup (1.5s), emits real-time SSE sync events, and enqueuesGenerateThumbnailJob+ProcessFileEmbeddingJob.
Aborting an Upload (DELETE /api/files/upload/:uploadId)
Section titled “Aborting an Upload (DELETE /api/files/upload/:uploadId)”Clients cancelling a transfer call DELETE /api/files/upload/:uploadId to immediately abort the S3 multipart upload or delete local chunks, release the Redis quota:pending:{userID}, and clear upload:parts:{sessionID}. Uncancelled abandoned sessions are swept automatically by the hourly UploadCleanupJob.