Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobsapps/ace04787d132ed44cc8a8cb209f06f70 to your computer and use it in GitHub Desktop.

Select an option

Save jacobsapps/ace04787d132ed44cc8a8cb209f06f70 to your computer and use it in GitHub Desktop.
func resumableUpload(videoURL: URL, sessionId: String, fileSize: Int64) async throws {
var offset = max(
startResponse.nextOffset,
await offsetStore.offset(for: sessionId)
)
while offset < fileSize {
do {
let chunkFile = try temporaryChunkFile(
sourceVideoURL: videoURL, offset: offset, length: Int(chunkSize)
)
let request = makeChunkRequest(
sessionId: sessionId, offset: offset, totalBytes: fileSize
)
_ = try await session.data(for: request)
offset += chunkFile.byteCount
await offsetStore.set(offset: offset, for: sessionId)
} catch {
offset = try await fetchRemoteOffset(sessionId: sessionId)
await offsetStore.set(offset: offset, for: sessionId)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment