如何通过Swift上传视频到Vimeo
我需要将视频文件上传到我的iOS应用程序中的Vimeo。 Vimeo的iOS库已弃用,因此我正在尝试在Vimeo开发人员网站上使用API上传视频。 https://developer.vimeo.com/api/api/upload/videos 我使用的是可重新吸收的方法。 总共有3个步骤。步骤1成功,步骤2仍在失败。 这是我在步骤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)")
}
}
}
当我这样做时,响应是“缺少或无效的内容类型标头”。 任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Alamofire和Apple的网络框架通常不支持上传的TUS协议。您要么需要手动实现该流并上传流,要么切换到Vimeo文档中概述的基于表单的方法。
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.