Vimeo视频上传API失败快速

时间:2020-05-07 08:06:27

标签: swift alamofire vimeo-api vimeo-ios

在我的项目中,我需要将视频上传到vimeo,并且我已经在vimeo中注册了一个企业帐户。我已使用https://developer.vimeo.com/api/upload/videos本教程在自己的项目中实施该教程。我正在按照可恢复的方式上传视频。

页眉将值设置为

Tus-Resumable 1.0.0 Upload-Offset 0 Content-Type application/offset+octet-stream Accept application/vnd.vimeo.*+json;version=3.4

Upload-Offset具有整数类型的数据,其他键具有字符串类型的内容。 我正在使用“ Alamofire”,“〜> 4.1”进行联网。 API响应返回状态码:412。

Content-Type是application / octet-stream,如何使用alamofire上传视频。我遇到了与数据不兼容的错误

用于调用API的函数

`func uploadVimeoVideo() {

    let UrlString       = self.m_strUploadLink

    let dicHeader  : [String : Any] = ["Tus-Resumable" : "1.0.0","Upload-Offset" : 0,"Content-Type" : "application/octet-stream","Accept" : "application/vnd.vimeo.*+json;version=3.4"]

    var videodata  : Data!

           Alamofire.upload(multipartFormData: { (multipartFormData) in

               do
               {
                   videodata = try Data(contentsOf: IN_strFileURL, options: .mappedIfSafe)

                   print(videodata)
               }
               catch
               {
                   print("Error")
               }

               if let data = videodata{
                   multipartFormData.append(data, withName: "file", fileName: "image.mp4", mimeType: "application/octet-stream")
               }

           }, usingThreshold: UInt64.init(), to: UrlString, method: .patch, headers: dicHeader as? HTTPHeaders) { (result) in
               switch result{
               case .success(let upload, _, _):
                   upload.responseString { response in
                       print("Succesfully uploaded",response)
                       var returnResult : NSDictionary = [:]
                       if let data = response.result.value
                       {

                           if INT_DEBUG_LOG == 1
                           {
                               let result = data
                               if let data = result.data(using: .utf8) {
                                   do {
                                       returnResult = try JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary
                                   } catch {
                                       print(error.localizedDescription)
                                   }
                               }

                               self.delegate?.DidFinishUploadVideo!(iSsuccess: true, IN_mutdicResponse: returnResult)
                           }

                       }

                       if let err = response.error{
                           let data = response.result.value
                           let result = data
                           if let data = result?.data(using: .utf8) {
                               do {
                                   returnResult = try JSONSerialization.jsonObject(with: data, options: []) as! NSDictionary
                               } catch {
                                   print(error.localizedDescription)
                               }
                           }
                           self.delegate?.DidFinishUploadVideo!(iSsuccess: false, IN_mutdicResponse: returnResult )
                           return
                       }

                   }
               case .failure(let error):
                   print("Error in upload: \(error.localizedDescription)")

               }
           }
}`

0 个答案:

没有答案