Skip to content

Commit 42b36fa

Browse files
committed
Updated the readme
1 parent 1c3be33 commit 42b36fa

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,29 @@ To upload multiple files at once, you can use the `uploadFiles(filePaths:)` meth
9898

9999
To specify a custom upload URL (e.g. for TransloadIt) or custom headers to be added to a file upload, please refer to the `uploadURL` and `customHeaders` properties in the methods related to uploading. Such as: `upload`, `uploadFileAt`, `uploadFiles` or `uploadMultiple(dataFiles:)`.
100100

101+
### Custom header generation
102+
103+
Sometimes headers need to be signed or refreshed right before a request is sent.
104+
`TUSClient` exposes a header generation hook so you can mutate previously supplied custom headers without rebuilding the upload. Pass the optional `generateHeaders` closure to the initializer and TUSKit will call it before every `POST`, `PATCH`, or `HEAD` request.
105+
106+
```swift
107+
let client = try TUSClient(
108+
server: serverURL,
109+
sessionIdentifier: "UploadSession",
110+
sessionConfiguration: configuration,
111+
storageDirectory: storageDirectory,
112+
supportedExtensions: [.creation]
113+
) { uploadID, headers, onHeadersGenerated in
114+
tokenProvider.fetchToken(for: uploadID) { token in
115+
var mutatedHeaders = headers
116+
mutatedHeaders["Authorization"] = "Bearer \(token)"
117+
onHeadersGenerated(mutatedHeaders)
118+
}
119+
}
120+
```
121+
122+
TUSKit will reuse whatever headers you return for automatic retries or when resuming an upload, ensuring the same values are applied consistently. New headers can be introduced as needed, while core TUS headers such as `Upload-Offset` and `Content-Length` remain under the SDK’s control.
123+
101124
## Measuring upload progress
102125

103126
To know how many files have yet to be uploaded, please refer to the `remainingUploads` property.

0 commit comments

Comments
 (0)