Der Server sendet korrekt eine Informationsantwort „104 Upload Resumption Supported, die ich in meinem Delegierten erhalte. Wenn ich jedoch die Upload-Aufgabe mit cancelByProducingResumeData() abbreche, wird immer Null zurückgegeben.
Setup
- iOS 18/26
- HTTP/2-Server mit TLS (mit SwiftNIO + Network.framework)
- Server implementiert das fortsetzbare Upload-Draft-Protokoll
Code: Select all
class VideoUploader: NSObject, URLSessionTaskDelegate, URLSessionDataDelegate {
private var urlSession: URLSession!
private var uploadTask: URLSessionUploadTask?
func uploadVideo(fileURL: URL) {
var request = URLRequest(url: URL(string: "https://localhost:3000/upload")!)
request.httpMethod = "POST"
request.setValue("?0", forHTTPHeaderField: "Upload-Incomplete")
request.setValue("3", forHTTPHeaderField: "Upload-Draft-Interop-Version")
uploadTask = urlSession.uploadTask(with: request, fromFile: fileURL)
uploadTask?.resume()
// Cancel after 3 seconds to test resume data
Task {
try? await Task.sleep(for: .seconds(3))
guard let uploadTask else { return }
let resumeData = await uploadTask.cancelByProducingResumeData()
print("Resume data: \(resumeData)") // Always prints nil
}
}
// This IS called - server sends 104 correctly
func urlSession(_ session: URLSession, task: URLSessionTask, didReceiveInformationalResponse response: HTTPURLResponse) {
print("Received 104: \(response.statusCode)")
print("Location: \(response.allHeaderFields["Location"] ?? "none")")
}
}
Hier sind einige Protokolle darüber, was passiert:
Code: Select all
[Uploader] Creating upload task to: https://localhost:3000/upload
[Uploader] Request method: POST
[Uploader] Request headers:
[Uploader] Upload-Length: 183083641
[Uploader] Upload-Complete: ?1
[Uploader] Upload-Draft-Interop-Version: 6
[Uploader] Upload task created with ID: 2
[Uploader] Upload task resumed
[TaskDelegate] Received authentication challenge: NSURLAuthenticationMethodServerTrust
[TaskDelegate] Received informational response!
[TaskDelegate] Status code: 104
[TaskDelegate] Informational response headers:
[TaskDelegate] Upload-Draft-Interop-Version: 6
[TaskDelegate] Location: /uploads/6123040065090238422-4871340930786507232
[TaskDelegate] Resume URL (Location): /uploads/6123040065090238422-4871340930786507232
[TaskDelegate] Progress: 5% - Sent 10529890/183083641 bytes (this chunk: 10529890 bytes)
[TaskDelegate] Progress: 11% - Sent 21029328/183083641 bytes (this chunk: 10499438 bytes)
[TaskDelegate] Progress: 17% - Sent 31385589/183083641 bytes (this chunk: 10356261 bytes)
[TaskDelegate] Progress: 17% - Sent 31501636/183083641 bytes (this chunk: 116047 bytes)
[Uploader] Cancelling upload
[Uploader] Task state before cancel: 0
[Uploader] Cancel completed
[Uploader] Resume data returned: NO
Mobile version