如何通过Swift上传视频到Vimeo

发布于 2025-02-07 20:31:56 字数 1463 浏览 1 评论 0原文

我需要将视频文件上传到我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2025-02-14 20:31:56

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文