Skip to content

Expose TUS upload chunk size#44

Merged
tim-kos merged 2 commits into
mainfrom
codex/tus-chunk-size-and-upload-docs
May 26, 2026
Merged

Expose TUS upload chunk size#44
tim-kos merged 2 commits into
mainfrom
codex/tus-chunk-size-and-upload-docs

Conversation

@tim-kos

@tim-kos tim-kos commented May 22, 2026

Copy link
Copy Markdown
Member

What changed

  • Adds tusUploadChunkSize to the Transloadit initializers and passes it through to TUSKit.
  • Allows apps to pass 0 to let TUSKit upload each file in one request, which can be useful for iOS background uploads where scheduling a new task for each 500 KiB chunk can stall.
  • Clarifies that createAssembly(... andUpload ..., completion:) fires after the Assembly is created and uploads are scheduled, not after file upload or processing completion.
  • Documents the recommended lifecycle: use TransloaditFileDelegate.didFinishUpload for upload completion and pollAssemblyStatus for processing completion.
  • Adds tests for the default chunk size, a custom chunk size, and the injected-signature initializer.

Why

A customer using TransloaditKit 3.5.0 saw didFinishUpload() fire while API2 had already aborted the Assembly after seeing only three default TUS chunks. Exposing the chunk size gives apps a way to avoid many small background URLSession tasks, and the docs now make the upload lifecycle explicit.

Validation

  • swift test

@tim-kos tim-kos changed the title [codex] Expose TUS upload chunk size Expose TUS upload chunk size May 26, 2026
@tim-kos tim-kos self-assigned this May 26, 2026
@tim-kos tim-kos marked this pull request as ready for review May 26, 2026 11:43
@tim-kos tim-kos merged commit fcfc91a into main May 26, 2026
1 check passed
@kvz

kvz commented Jun 2, 2026

Copy link
Copy Markdown
Member

@donnywals can you review this in hindsight please

@donnywals

Copy link
Copy Markdown
Collaborator

Looks okay overall with one caveat; if we decide to change the default chunk size in TUSKit, we have to also update TransloaditKit with the same value (the 500 * 1024 value is currently the default in TUSKit).

One way to avoid this is to make nil the default chunk size instead of 500 * 1024. If the user didn't pass a chunk size, we don't pass a chunk size to TUSKit and we get its default. For any non-nil value we pass the user's choice explicitly.

It'd roughly look like this when building the TUSKit client:

lazy var tusClient: TUSClient = {
  let tusClient: TUSClient
  if let tusUploadChunkSize {
    tusClient = try! TUSClient(
      server: URL(string:"https://www.transloadit.com")!,
      sessionIdentifier: "TransloadIt",
      sessionConfiguration: tusSessionConfig,
      storageDirectory: storageDir,
      chunkSize: tusUploadChunkSize
    )
  } else {
    tusClient = try! TUSClient(
      server: URL(string:"https://www.transloadit.com")!,
      sessionIdentifier: "TransloadIt",
      sessionConfiguration: tusSessionConfig,
      storageDirectory: storageDir
    )
  }
  tusClient.delegate = self
  return tusClient
}()

I think there's an argument to be made for the current approach being more explicit, and for each SDK to control its own default, I think it's important to make this decision and to decide whether that's the behavior we want, or if we want to consider the user's choice to not set a chunk size to equal "let TUSKit decide".

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.

3 participants