Reputation: 43
I need to upload a video file to vimeo from my ios app. Vimeo's iOS library is deprecated, so I'm trying to upload a video using the api on the Vimeo developer site. https://developer.vimeo.com/api/upload/videos I'm using the resumable approach. There are 3 steps in total. Step 1 was successful and step 2 is still failing. Here's the method I tried in step 2:
private func uploadVideoToVimeo(uploadLink:String) {
let urlString = uploadLink
let headers: HTTPHeaders = [ "Tus-Resumable":"1.0.0",
"Upload-Offset": "0",
"Content-Type": "application/offset+octet-stream",
"Accept":"application/vnd.vimeo.*+json;version=3.4"]
var request = URLRequest(url: URL(string: urlString)!)
request.headers = headers
request.method = .patch
AF.upload(multipartFormData: { multipartFormData in
let timestamp = NSDate().timeIntervalSince1970
do {
let data = try Data(contentsOf: self.videoLocalURL, options:.mappedIfSafe)
print("data size :\(data)")
multipartFormData.append(data, withName: "\(timestamp)")
} catch {}
}, with: request).responseString { response in
switch response.result {
case .success(let data):
print("esponse :\(response)")
case let .failure(error):
print("ERROR :\(error)")
}
}
}
When I do this, the response is “missing or invalid Content-Type header”. Any help would be greatly appreciated.
Upvotes: 0
Views: 248
Reputation: 12770
Alamofire, and Apple's network frameworks in general, don't support the TUS protocol for uploads. You either need to implement that manually and upload a stream, or switch to using the form-based approach outlined in the Vimeo docs.
Upvotes: 1