-
Notifications
You must be signed in to change notification settings - Fork 124
Open
Description
Hello,
I'm encountering an issue when using background file uploads with token-based authorization.
In my app, uploads are authorized via a bearer token. For testing purposes, I've set short-lived tokens (30 seconds) to simulate token expiry during background uploads.
Each time an error occurs due to an expired token, I refresh the token manually, recreate the URLSessionConfiguration with the new token, and then reinitialize the TUSClient. This is necessary, otherwise the internal URLSession in TUSClient continues using the old token from its original configuration.
Setup example:
let urlSessionConfig = URLSessionConfiguration
.background(withIdentifier: sessionId.uuidString)
urlSessionConfig.httpAdditionalHeaders = [
"Authorization": accessAPIToken.token
]
tusClient = try TUSClient(
server: tusServerURL,
sessionIdentifier: UUID().uuidString,
sessionConfiguration: urlSessionConfig,
storageDirectory: tusDirectory
)The issue
- When the token expires and I recreate the
TUSClientwith a new session config and token: - The upload fails silently - no error is delivered via
URLSessionDataDelegateorTUSClient. - The upload does not resume.
- No error message is available, which leads to the app becoming stuck in a hanging state.
- Calling
stopAndCancelAll()doesn’t resolve the issue. - It seems that after recreating the client, the error from the background session is no longer captured.
Questions / Suggestions
- Would it be possible to allow passing a delegate explicitly to
TUSClient, so background errors can be handled externally? - Is there a recommended way to refresh the token without recreating the whole
URLSessionConfigurationorTUSClient? - Alternatively, is there a way to invalidate and recreate a
URLSessionwith a new header while keeping the same background identifier?
Any advice or guidance would be greatly appreciated - thank you!
Metadata
Metadata
Assignees
Labels
No labels
