title: Uploading video to server with alamofire 5 Swift 5
body: <p>I need help for uploading videos to my server with alamofire 5</p>
  <blockquote>
  <p>1 Multiple images uploaded successfully with this code.</p>
  <p>2 I am using <code>TLPHAsset</code> for image/video selection.</p>
  </blockquote>
  <h2>Note: Text is uploaded successfully only video is not uploaded. I have received a response with success.</h2>
  <p>Here is my sample code</p>
  <pre><code>func apiCallWithMultipart(arrMedia:[TLPHAsset], completionHandler: @escaping (DataResponse&lt;Any&gt;) -&gt; Void) {
  
      
      if VVSingleton.sharedInstance.isReachable {
          // Show HUD
          VVSingleton.sharedInstance.showHUDWithText(strText: &quot;Please wait...&quot;)
          //            VVSingleton.sharedInstance.showHUDWithText(strText: &quot;Loading \(url.absoluteString.split(separator: &quot;/&quot;).last ?? &quot;&quot;)&quot;)
          
          headers = createHeadersMultipart()
          
          DispatchQueue.main.async {
              AF.upload(multipartFormData: { (multipartFormData) in
                  // Add parameters
                  for (key, value) in self.parameters {
                      let paramValue = &quot;\(value)&quot; as String
                      multipartFormData.append(paramValue.data(using: String.Encoding.utf8, allowLossyConversion: false)!, withName: key as String)
                  }
                  
                  for media in arrMedia {
                      if media.type == TLPHAsset.AssetType.video {
                          media.phAsset?.requestContentEditingInput(with: PHContentEditingInputRequestOptions(), completionHandler: { (phContentEditingInput, [AnyHashable : Any]) in
                              
                              if let videoURL = (phContentEditingInput!.audiovisualAsset as? AVURLAsset)?.url {
                                  if videoURL.isFileURL {
                                      
  //                                        do {
  //                                            let videoData = try Data(contentsOf: videoURL, options: .mappedIfSafe)
  //                                            print(videoData)
  //                                            //  here you can see data bytes of selected video, this data object is upload to server by multipartFormData upload
  //                                            multipartFormData.append(videoData, withName: &quot;album_files[]&quot;, fileName: media.originalFileName, mimeType: media.MIMEType(videoURL))
  //                                        } catch  {
  //                                            print(&quot;error while create data = \(error)&quot;)
  //                                        }
  
                                      
                                      //print(&quot;\(videoURL)&quot; + media.originalFileName!)
                                      multipartFormData.append(videoURL, withName: &quot;album_files[]&quot;, fileName: media.originalFileName ?? &quot;Sample&quot;, mimeType: media.MIMEType(videoURL)!)
                                      
                                      //multipartFormData.append(videoURL, withName: &quot;unicorn&quot;)
                                  }
                              }
                          })
                      }
                      else if media.type == TLPHAsset.AssetType.photo {
                          let imageData = media.fullResolutionImage?.jpegData(compressionQuality: 1)
                          if let data = imageData {
                              multipartFormData.append(data, withName: &quot;album_files[]&quot;, fileName: &quot;\(Date().timeIntervalSince1970).jpg&quot;, mimeType: MimeType_jpg)
                          }
                      }
                  }
                  
                  
                  
              }, usingThreshold: UInt64.init(), fileManager: FileManager.default, to: self.url, method: HTTPMethod.post, headers: self.headers)
                  
                  
                  .uploadProgress { progress in // main queue by default
                      print(&quot;Upload Progress: \(progress.fractionCompleted)&quot;)
                      print(&quot;Upload Estimated Time Remaining: \(String(describing: progress.estimatedTimeRemaining))&quot;)
                      print(&quot;Upload Total Unit count: \(progress.totalUnitCount)&quot;)
                      print(&quot;Upload Completed Unit Count: \(progress.completedUnitCount)&quot;)
                  }
                  
                  .responseJSON { (response) in
                      // Error Handle : https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#response-handling
                      
                      //            #file          String   The name of the file in which it appears.
                      //            #line          Int      The line number on which it appears.
                      //            #column        Int      The column number in which it begins.
                      //            #function      String   The name of the declaration in which it appears.
                      //            #dsohandle     String   The dso handle.
                      print(&quot;\n\n\nFile -&gt; \(#file), Function -&gt; \(#function), Line -&gt; \(#line)\n&quot;)
                      print(&quot;Request: \(String(describing: response.request))&quot;)   // original url request
                      print(&quot;Parameters: \(self.parameters.description)&quot;)   // original url request
                      //print(&quot;Response: \(String(describing: response.response))&quot;) // http url response
                      //print(&quot;Result: \(response.result)&quot;)                         // response serialization result
                      
                      if let data = response.data, let utf8Text = String(data: data, encoding: .utf8) {
                          print(&quot;String Data: \(utf8Text)&quot;) // original server data as UTF8 string
                      }
                      
                      if let json = response.value {
                          print(&quot;JSON Response : \(json)&quot;) // serialized json response
                      }
                      
                      // Hide HUD
                      //                    DispatchQueue.main.asyncAfter(deadline: .now()) {
                      // your code here
                      if Thread.isMainThread {
                          VVSingleton.sharedInstance.hideHUD()
                      }
                      else {
                          DispatchQueue.main.async {
                              VVSingleton.sharedInstance.hideHUD()
                          }
                      }
                      
                      completionHandler(response)
              }
          }
      } else {
          // Show Network error
          VVSingleton.sharedInstance.showAlertMessage(TitleString: &quot;Network Error&quot;, AlertMessage: &quot;Your device is not connected to the Internet&quot;, viewController: delegate)
      }
  }
  </code></pre>
  <p><strong>Log of uploading progress</strong></p>
  <pre><code>Upload Progress: 1.0
  Upload Estimated Time Remaining: nil
  Upload Total Unit count: 885
  Upload Completed Unit Count: 885
  </code></pre>