title: Adding headers to Alamofire multiPartFormData upload
body: <p>Been having difficulties trying to figure this one out. Post requests using Alamofire (4.4.0) and my headers work fine for most things, however this time I need to send up a dictionary of Strings, as well as a video.</p>
  
  <p>The video is recorded via a UIImagePickerController, and the info that eventually makes it to the dictionary is created via a series of sliders, switches, and text fields. </p>
  
  <p>The block that is given me trouble is as follows:</p>
  
  <pre><code>let headers: HTTPHeaders = [
          "X-Access-Token": self.user
      ]
  let requestUrl = try! URLRequest(url: "http://exampleUrl.com", method: .post, headers: headers)
  
      upload(
          multipartFormData: { (multipartFormData) in
              multipartFormData.append(videoURL!, withName: "video_source")
              multipartFormData.append(self.alphaLabel.text!.data(using: .utf8)!, withName: "alpha")
              multipartFormData.append(self.betaLabel.text!.data(using: .utf8)!, withName: "beta")
              multipartFormData.append(self.gammaLabel.text!.data(using: .utf8)!, withName: "gamma")
              multipartFormData.append(self.deltaTextField.text!.data(using: .utf8)!, withName: "delta")
              multipartFormData.append(self.epsilonScrollPicker.data(using: .utf8)!, withName: "epsilon")
              multipartFormData.append(zetaArray!.data(using: .utf8)!, withName: "zeta")
  
          },
              to: requestUrl as! URLConvertible) { encodingResult in
                  switch encodingResult {
                  case .success (let upload, _, _):
                      upload.responseJSON { response in
                          print(response)
                      }
                  case .failure (let encodingError):
                      print(encodingError)
              }
         }
  </code></pre>
  
  <p>The code above gives: 
  "Thread 1: signal SIGABRT"</p>
  
  <p>The console outputs: 
  "Could not cast value of type 'Foundation.URLRequest' to 'Alamofire.URLConvertible'."</p>
  
  <p>To check to see if everything else works, I ran this: </p>
  
  <pre><code>let requestUrl "http://exampleUrl.com"
  
  upload(
      multipartFormData: { (multipartFormData) in
          multipartFormData.append(videoURL!, withName: "video_source")
          multipartFormData.append(self.alphaLabel.text!.data(using: .utf8)!, withName: "alpha")
          multipartFormData.append(self.betaLabel.text!.data(using: .utf8)!, withName: "beta")
          multipartFormData.append(self.gammaLabel.text!.data(using: .utf8)!, withName: "gamma")
          multipartFormData.append(self.deltaTextField.text!.data(using: .utf8)!, withName: "delta")
          multipartFormData.append(self.epsilonScrollPicker.data(using: .utf8)!, withName: "epsilon")
          multipartFormData.append(zetaArray!.data(using: .utf8)!, withName: "zeta")
  
      },
          to: requestUrl as! URLConvertible) { encodingResult in
              switch encodingResult {
              case .success (let upload, _, _):
                  upload.responseJSON { response in
                      print(response)
                  }
              case .failure (let encodingError):
                  print(encodingError)
  
  
          }
      }
  </code></pre>
  
  <p>If I use a different request Url, one without other parameters, I get a 401 - invalid access token from my server. This is to be expected as I am not able to pass one up in the header with this new request.</p>
  
  <p>If anyone can shed light on how to do an upload multiPartFormData request <strong>and</strong> have a header included for authentication I would appreciate it. </p>