Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload task cancelled without resumedata #9

Open
swapna-cheera opened this issue Jan 7, 2025 · 4 comments
Open

Upload task cancelled without resumedata #9

swapna-cheera opened this issue Jan 7, 2025 · 4 comments

Comments

@swapna-cheera
Copy link

I have cloned the repos and run them as it is server - Swift NIO and client iOS it's always cancelled without resumedata.

@Acconut
Copy link
Member

Acconut commented Jan 8, 2025

Without more details it's hard to troubleshoot here, but it's not unlikely that the Swift NIO example in this repository is not compatible with latest iOS versions anymore. Newer iOS releases have upgraded their version for resumable uploads while this example was not updated anymore.

However, the Swift NIO implementation for resumable uploads has been merged into swift-nio-extras and is maintained as HTTPResumableUploadHandler there: https://github.com/apple/swift-nio-extras/tree/main?tab=readme-ov-file#current-contents I would recommend you to give it a try. I would like to update the example in this repository to use the new implementation, but I'm not sure when I will have time.

I hope this helps.

@swapna-cheera
Copy link
Author

I have cloned the repository and run the swift-nio, go servers and from client iOS app when I'm trying to upload video, it's always cancelled without resumable data

it's always "No resume data available"

`//
// VideoUploader.swift
// ResumableVideoUpload

import Foundation
import AVFoundation

class VideoUploader: NSObject {
private var uploadTask: URLSessionUploadTask?
private var resumeData: Data?

override init() {
}

func uploadVideo(fileURL: URL) {
    var request = URLRequest(url: URL(string: "http://localhost:8080/upload")!)
    request.httpMethod = "POST"
    request.setValue("video/mp4", forHTTPHeaderField: "Content-Type")

    uploadTask = URLSession.shared.uploadTask(with: request, fromFile: fileURL) { data, response, error in
        if let error = error {
            print("Upload error: \(error)")
            return
        }
        if let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 {
            print("Video uploaded successfully!")
        } else {
            print("Failed to upload video. Response: \(String(describing: response))")
        }
    }
    uploadTask?.resume()
}

func pauseUpload() {
    uploadTask?.cancel(byProducingResumeData: { data in
        if let resumeData = data {
            self.resumeData = resumeData
            print("Resume Data: \(resumeData)")
        } else {
            print("No resume data available.")
        }
    })
}

func resumeUpload() {
    if let resumeData = resumeData {
        uploadTask = URLSession.shared.uploadTask(withResumeData: resumeData)
        uploadTask?.resume()
        self.resumeData = nil
    } else {
        print("No upload to resume.")
    }
}

}
`

@Acconut
Copy link
Member

Acconut commented Jan 14, 2025

I have cloned the repository and run the swift-nio, go servers and from client iOS app when I'm trying to upload video, it's always cancelled without resumable data

I don't understand. Did you use the server from https://github.com/apple/swift-nio-extras or not?

@swapna-cheera
Copy link
Author

swapna-cheera commented Jan 16, 2025

Yes, I have updated now it's working. Pull request : #10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants