Skip to main content

upload(segments, manifest, options)

Encrypts HLS segments in the browser and uploads them to S3 via presigned URLs. Parameters:
ParameterTypeDescription
segmentsSegmentInput[]Array of HLS segments to encrypt and upload
manifeststringThe .m3u8 manifest text
optionsUploadOptionsConfiguration for the upload
Returns: Promise<Result<UploadResult, UploaderError>>

UploadOptions

interface UploadOptions {
  /** Unique identifier for this content (used for key derivation) */
  contentId: string

  /** Base URL of the BlindCast key server */
  keyServerUrl: string

  /** URL of the presign endpoint */
  presignUrl: string

  /** Returns a Bearer token for auth (called for key fetch and presign requests) */
  auth?: () => Promise<string>

  /** Called after each segment is uploaded */
  onProgress?: (progress: UploadProgress) => void

  /** AbortSignal to cancel the upload */
  signal?: AbortSignal

  /** Number of parallel uploads (default: 4) */
  concurrency?: number

  /** S3 key prefix (default: "content/<contentId>/") */
  prefix?: string
}

SegmentInput

interface SegmentInput {
  /** Segment number (used for IV derivation) */
  index: number

  /** Raw .ts segment bytes (plaintext — will be encrypted) */
  data: Uint8Array

  /** Original filename (e.g., "seg-0.ts") */
  filename: string
}

UploadResult

interface UploadResult {
  /** URL of the uploaded (rewritten) manifest */
  manifestUrl: string

  /** URLs of uploaded encrypted segments, in order */
  segmentUrls: string[]

  /** Total number of segments uploaded */
  segmentCount: number
}

UploadProgress

interface UploadProgress {
  /** Number of segments uploaded so far */
  completed: number

  /** Total number of segments */
  total: number

  /** Filename of the segment just uploaded */
  current: string
}

Error codes

CodeCause
KEY_FETCH_FAILEDCould not fetch content key from key server
ENCRYPT_FAILEDSegment encryption failed
PRESIGN_FAILEDPresign endpoint returned an error or non-200 status
UPLOAD_FAILEDS3 upload failed (network error or rejected)
MANIFEST_PARSE_ERRORThe manifest text is not valid HLS
INVALID_INPUTSegments array is empty, contentId is invalid, or segment data is missing
ABORTEDUpload was cancelled via AbortSignal
See Error Codes for all error codes across BlindCast.