Skip to content

Commit 9c51d16

Browse files
committed
Fixed an issue with upload progress reporting
1 parent 92cca93 commit 9c51d16

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 3.4.3
2+
3+
## Bugfix
4+
- Fixed an issue where the total progress was not being updated correctly when using chunked uploads.
5+
- Fixed an issue where total progress would not include in progress uploads.
6+
17
# 3.4.2
28

39
## Bugfix

Sources/TUSKit/TUSClient.swift

+9-5
Original file line numberDiff line numberDiff line change
@@ -716,11 +716,15 @@ extension TUSClient: ProgressDelegate {
716716
func progressUpdatedFor(metaData: UploadMetadata, totalUploadedBytes: Int) {
717717
delegate?.progressFor(id: metaData.id, context: metaData.context, bytesUploaded: totalUploadedBytes, totalBytes: metaData.size, client: self)
718718

719-
var totalBytesUploaded: Int = 0
720-
var totalSize: Int = 0
721-
for (_, metaData) in uploads {
722-
totalBytesUploaded += metaData.uploadedRange?.count ?? 0
723-
totalSize += metaData.size
719+
var totalBytesUploaded: Int = totalUploadedBytes
720+
var totalSize: Int = metaData.size
721+
for (_, metaDataForTotal) in uploads {
722+
guard metaDataForTotal.id != metaData.id else {
723+
continue
724+
}
725+
726+
totalBytesUploaded += metaDataForTotal.uploadedRange?.count ?? 0
727+
totalSize += metaDataForTotal.size
724728
}
725729

726730
delegate?.totalProgress(bytesUploaded: totalBytesUploaded, totalBytes: totalSize, client: self)

Sources/TUSKit/Tasks/UploadDataTask.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class UploadDataTask: NSObject, IdentifiableTask {
106106
sessionTask = task
107107

108108
if #available(iOS 11.0, macOS 10.13, *) {
109-
observeTask(task: task, size: dataSize)
109+
observeTask(task: task, size: range?.count ?? dataSize)
110110
}
111111
}
112112

TUSKitExample/TUSKitExample/Helpers/TUSWrapper.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class TUSWrapper: ObservableObject {
7676
extension TUSWrapper: TUSClientDelegate {
7777
func progressFor(id: UUID, context: [String: String]?, bytesUploaded: Int, totalBytes: Int, client: TUSClient) {
7878
Task { @MainActor in
79+
print("progress for \(id): \(bytesUploaded) / \(totalBytes) => \(Int(Double(bytesUploaded) / Double(totalBytes) * 100))%")
7980
uploads[id] = .uploading(bytesUploaded: bytesUploaded, totalBytes: totalBytes)
8081
}
8182
}
@@ -111,7 +112,9 @@ extension TUSWrapper: TUSClientDelegate {
111112
}
112113

113114
func fileError(error: TUSClientError, client: TUSClient) { }
114-
func totalProgress(bytesUploaded: Int, totalBytes: Int, client: TUSClient) { }
115+
func totalProgress(bytesUploaded: Int, totalBytes: Int, client: TUSClient) {
116+
print("total progress: \(bytesUploaded) / \(totalBytes) => \(Int(Double(bytesUploaded) / Double(totalBytes) * 100))%")
117+
}
115118
}
116119

117120

0 commit comments

Comments
 (0)