mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat: chunked (S3 multipart) uploads for R2/S3 video backend
Self-hosted instances on the R2/S3 backend could only upload a video as a single PUT, which fails behind a Cloudflare proxy/tunnel (100MB request-body cap) and is capped at 5GiB with no resilience. Bunny already avoids this via tus; this brings the R2/S3 path to parity. Files larger than a threshold (default 90MiB) are now split into parts (default 32MiB, min 5MiB) and uploaded directly browser->R2 via presigned UploadPart URLs, then reassembled server-side with CompleteMultipartUpload. Each request stays under the 100MB cap, lifts the size ceiling well past 5GiB, and adds per-chunk retry. Files at/under the threshold keep the existing single-PUT path unchanged. Bunny path is untouched. Thresholds are env-overridable via OPENFRAME_R2_MULTIPART_THRESHOLD_BYTES and OPENFRAME_R2_MULTIPART_PART_SIZE_BYTES. Verified end-to-end against real Cloudflare R2 and a local MinIO behind an nginx 90MB cap (single 141MB PUT 413s on master; 32MB parts pass here). Closes #22
This commit is contained in:
@@ -97,3 +97,36 @@ export function getMaxVideoUploadBytes(): bigint {
|
||||
export function isInviteCodeRequired() {
|
||||
return readBooleanEnv('OPENFRAME_REQUIRE_INVITE_CODE', true);
|
||||
}
|
||||
|
||||
function parseBigIntEnv(name: string, defaultValue: bigint, minValue?: bigint): bigint {
|
||||
const raw = process.env[name]?.trim();
|
||||
if (!raw) return defaultValue;
|
||||
|
||||
try {
|
||||
const parsed = BigInt(raw);
|
||||
if (parsed <= BigInt(0)) return defaultValue;
|
||||
if (minValue !== undefined && parsed < minValue) return minValue;
|
||||
return parsed;
|
||||
} catch {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Files larger than this use S3 multipart upload (chunked) instead of a single PUT.
|
||||
// Default 90 MiB keeps each request under the common 100 MB Cloudflare proxy/tunnel cap.
|
||||
export function getR2MultipartThresholdBytes(): bigint {
|
||||
return parseBigIntEnv(
|
||||
'OPENFRAME_R2_MULTIPART_THRESHOLD_BYTES',
|
||||
BigInt(90) * BigInt(1024) * BigInt(1024)
|
||||
);
|
||||
}
|
||||
|
||||
// Size of each multipart chunk. Clamped to the S3 minimum of 5 MiB for non-final parts.
|
||||
export function getR2MultipartPartSizeBytes(): bigint {
|
||||
const minPartSize = BigInt(5) * BigInt(1024) * BigInt(1024);
|
||||
return parseBigIntEnv(
|
||||
'OPENFRAME_R2_MULTIPART_PART_SIZE_BYTES',
|
||||
BigInt(32) * BigInt(1024) * BigInt(1024),
|
||||
minPartSize
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user