GigHive bee gighive

Direct Streaming Implementation Plan (iPhone 12–safe)

This document describes the concrete steps and design choices for switching GigHive uploads to direct streaming (no full file in RAM) while preserving diagnostics and compatibility with iPhone 12 (iOS 14+).


Scope


Compatibility (iPhone 12 baseline)


Guardrails & Behavior

  1. No full-file reads (no Data(contentsOf:) for media).
  2. Disk headroom preflight:
    • Required ≈ videoSize + 5 MB (headers + footer, conservative).
    • Safety margin: + 200 MB (configurable).
    • If insufficient, show alert and abort before assembly.
  3. Multipart assembly on disk (Layer 1):
    • Create multipart-<UUID>.tmp in temporaryDirectory.
    • Write leading boundary + text fields.
    • Stream video bytes in 1–4 MB chunks into the multipart file.
    • Write closing boundary; close handle; record file size.
  4. Upload from file (Layer 2):
    • Build URLRequest with Content-Type: multipart/form-data; boundary=... and Basic Auth.
    • Use URLSession.uploadTask(with: request, fromFile: tempBodyURL).
    • Observe task.progress for realtime UI updates.
    • On completion/cancel/failure, delete tempBodyURL.
  5. Backgrounding (optional):
    • If enabled in settings, use background URLSessionConfiguration.background for reliability.
  6. Resumability (optional):
    • PHP multipart cannot resume mid-stream.
    • Keep TUS path for very large files (> 2 GB) if desired; otherwise use streaming for all.

Acceptance Tests

  1. Small video (Photos): size visible, upload succeeds, stable memory.
  2. Large video (Photos): if not local → picker error; when local → upload streams with progress.
  3. Files picker path: same behavior and stability.
  4. Low disk: preflight aborts with friendly alert, no crash.
  5. Backgrounding (if enabled): upload continues; completion received later.
  6. Network drop: graceful failure; (optional TUS path should resume if retained).

Files Touched


Decision Defaults (can be changed later)