Vimeo Video Upload API Failed Swift

396 Views Asked by At

In my project i need to upload a video to vimeo and i have taken a business account in vimeo. I have used https://developer.vimeo.com/api/upload/videos this tutorial for implementing it in my project. I am following resumable approach for uploading video.

Header Set value to

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

Upload-Offset has an integer type data other key has string type content. I am using 'Alamofire', '~> 4.1’ for networking. API response return Status Code: 412.

Content-Type is application/octet-stream,How to upload video using alamofire.i am getting error incompatible data type

Function used to call 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

There are 0 best solutions below