Skip to content

Commit

Permalink
Fixed an issue with upload progress reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
donnywals committed Jan 24, 2025
1 parent 92cca93 commit 9c51d16
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.4.3

## Bugfix
- Fixed an issue where the total progress was not being updated correctly when using chunked uploads.
- Fixed an issue where total progress would not include in progress uploads.

# 3.4.2

## Bugfix
Expand Down
14 changes: 9 additions & 5 deletions Sources/TUSKit/TUSClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,15 @@ extension TUSClient: ProgressDelegate {
func progressUpdatedFor(metaData: UploadMetadata, totalUploadedBytes: Int) {
delegate?.progressFor(id: metaData.id, context: metaData.context, bytesUploaded: totalUploadedBytes, totalBytes: metaData.size, client: self)

var totalBytesUploaded: Int = 0
var totalSize: Int = 0
for (_, metaData) in uploads {
totalBytesUploaded += metaData.uploadedRange?.count ?? 0
totalSize += metaData.size
var totalBytesUploaded: Int = totalUploadedBytes
var totalSize: Int = metaData.size
for (_, metaDataForTotal) in uploads {
guard metaDataForTotal.id != metaData.id else {
continue
}

totalBytesUploaded += metaDataForTotal.uploadedRange?.count ?? 0
totalSize += metaDataForTotal.size
}

delegate?.totalProgress(bytesUploaded: totalBytesUploaded, totalBytes: totalSize, client: self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/TUSKit/Tasks/UploadDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ final class UploadDataTask: NSObject, IdentifiableTask {
sessionTask = task

if #available(iOS 11.0, macOS 10.13, *) {
observeTask(task: task, size: dataSize)
observeTask(task: task, size: range?.count ?? dataSize)
}
}

Expand Down
5 changes: 4 additions & 1 deletion TUSKitExample/TUSKitExample/Helpers/TUSWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class TUSWrapper: ObservableObject {
extension TUSWrapper: TUSClientDelegate {
func progressFor(id: UUID, context: [String: String]?, bytesUploaded: Int, totalBytes: Int, client: TUSClient) {
Task { @MainActor in
print("progress for \(id): \(bytesUploaded) / \(totalBytes) => \(Int(Double(bytesUploaded) / Double(totalBytes) * 100))%")
uploads[id] = .uploading(bytesUploaded: bytesUploaded, totalBytes: totalBytes)
}
}
Expand Down Expand Up @@ -111,7 +112,9 @@ extension TUSWrapper: TUSClientDelegate {
}

func fileError(error: TUSClientError, client: TUSClient) { }
func totalProgress(bytesUploaded: Int, totalBytes: Int, client: TUSClient) { }
func totalProgress(bytesUploaded: Int, totalBytes: Int, client: TUSClient) {
print("total progress: \(bytesUploaded) / \(totalBytes) => \(Int(Double(bytesUploaded) / Double(totalBytes) * 100))%")
}
}


Expand Down

0 comments on commit 9c51d16

Please sign in to comment.