Skip to content

feat: add upload progress callbacks for queue API#2

Merged
tomershlasky merged 3 commits intomainfrom
feat/upload-progress-callbacks
Mar 16, 2026
Merged

feat: add upload progress callbacks for queue API#2
tomershlasky merged 3 commits intomainfrom
feat/upload-progress-callbacks

Conversation

@tomershlasky
Copy link
Copy Markdown
Collaborator

@tomershlasky tomershlasky commented Mar 16, 2026

Summary

Adds upload progress tracking to the Queue API so callers can show real-time upload progress (e.g., a progress bar) when submitting large video files.

Upload Progress Callbacks

  • New UploadProgressListener fun interface in QueueTypes.kt — a single onProgress(bytesWritten, totalBytes) callback
  • New optional onUploadProgress parameter on all three submission methods:
    • submit(model, input, onUploadProgress)
    • submitAndPoll(model, input, onStatusChange, onUploadProgress)
    • submitAndObserve(model, input, onUploadProgress)
  • Implemented via ProgressRequestBody — a standard OkHttp pattern that wraps the multipart body with a ForwardingSink counting bytes as they're written to the network
  • totalBytes is the full multipart content length when known, or -1 for InputStream inputs where size is unknown
  • All parameters are optional with null default — fully backward-compatible, no breaking changes

Sample App

  • Queue tab now shows a LinearProgressIndicator with "Uploading... X%" during file upload
  • Progress bar automatically hides once the upload completes and server-side processing begins

Changed Files

File Change
sdk/.../queue/QueueTypes.kt Added UploadProgressListener fun interface
sdk/.../queue/QueueClient.kt Added ProgressRequestBody, onUploadProgress param on submit/submitAndPoll/submitAndObserve
sdk/.../DecartClient.kt Trim API key on init
sample/.../MainActivity.kt Upload progress bar UI in Queue tab
sdk/.../queue/QueueClientTest.kt 10 new tests for upload progress

Usage

// Simple lambda syntax (UploadProgressListener is a fun interface)
client.queue.submit(model, input) { bytesWritten, totalBytes ->
    if (totalBytes > 0) {
        val percent = (bytesWritten * 100 / totalBytes).toInt()
        Log.d("Upload", "Progress: $percent%")
    }
}

// With submitAndObserve (Flow)
client.queue.submitAndObserve(model, input) { bytesWritten, totalBytes ->
    updateProgressBar(bytesWritten.toFloat() / totalBytes)
}.collect { update ->
    when (update) {
        is QueueJobResult.InProgress -> showStatus(update.status)
        is QueueJobResult.Completed  -> saveVideo(update.data)
        is QueueJobResult.Failed     -> showError(update.error)
    }
}

Test plan

  • Run ./gradlew sdk:test — all tests pass including 10 new upload progress tests
  • Build and install sample app on emulator/device
  • In sample app: Video tab → select video → submit → verify upload progress bar appears with percentage
  • Verify progress bar disappears once status switches to PENDING/PROCESSING

@tomershlasky tomershlasky merged commit 75df5fc into main Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant