0

在我的项目中,我需要将视频上传到 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)")

               }
           }
}`
4

0 回答 0