Created
March 4, 2026 12:00
-
-
Save jacobsapps/a91e64d2d73edc5e766bc1aa94bbde16 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func uploadChunks(videoURL: URL, sessionId: String, fileSize: Int64) async throws { | |
| var offset: Int64 = 0 | |
| let chunkSize: Int64 = 512 * 1024 | |
| while offset < fileSize { | |
| let handle = try FileHandle(forReadingFrom: videoURL) | |
| defer { try? handle.close() } | |
| try handle.seek(toOffset: UInt64(offset)) | |
| let chunkData = try handle.read(upToCount: Int(min(chunkSize, fileSize - offset))) ?? Data() | |
| let chunkFile = FileManager.default.temporaryDirectory | |
| .appendingPathComponent("chunk-\(UUID().uuidString).bin") | |
| try chunkData.write(to: chunkFile) | |
| let request = makeChunkRequest(sessionId: sessionId, offset: offset, totalBytes: fileSize) | |
| let task = session.uploadTask(with: request, fromFile: chunkFile) | |
| task.resume() | |
| offset += Int64(chunkData.count) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment