title: Alamofire add parameters to multi part request
body: <p>I am trying to add prameters to multi part request but without success, any suggestion.</p>
  
  <p>Compiler says value of type 'Any' has no member 'data'</p>
  
  <p><a href="https://i.stack.imgur.com/s3hO5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s3hO5.png" alt="enter image description here"></a></p>
  
  <pre><code>func createRep(_ question: String, type: String, anonymous: Bool, votesRequired: String, firstType: String, firstText: String, firstMedia: UIImage, secondType: String, secondText: String, secondMedia: UIImage, completionHandler: @escaping (APIResult&lt;Any&gt;) -&gt; Void)
    {
      let parameters: Parameters = [
        JSONKey.question.rawValue: question,
        JSONKey.type.rawValue: type,
        JSONKey.anonymous.rawValue: anonymous,
        JSONKey.votesRequired.rawValue: votesRequired,
        JSONKey.firstType.rawValue: firstType,
        JSONKey.firstText.rawValue: firstText,
        JSONKey.firstMedia.rawValue: firstMedia,
        JSONKey.secondType.rawValue: secondType,
        JSONKey.secondText.rawValue: secondText,
        JSONKey.secondMedia.rawValue: secondMedia
      ]
  
      let headers: HTTPHeaders = [
        "Authorization": "Bearer " + keychainService.getToken(),
        "Accept": "application/json"
      ]
  
      let url = EndPoint.baseUrl.rawValue + EndPoint.reps.rawValue
  
      let urlRep = try! URLRequest(url: url, method: .post, headers: headers)
  
      Alamofire.upload(multipartFormData: { (multipartFormData) in
  
        for (key, value) in parameters {
          multipartFormData.append(value.data(using: .utf8)!, withName: key)
        }
  
        if let firstMediaData = UIImagePNGRepresentation(firstMedia), let secondMediaData = UIImagePNGRepresentation(secondMedia) {
          multipartFormData.append(firstMediaData, withName: "firstMedia", fileName: "firstMedia", mimeType: "image/png")
          multipartFormData.append(secondMediaData, withName: "secondMedia", fileName: "secondMedia", mimeType: "image/png")
        }
  
        }, with: urlRep, encodingCompletion: { encodingResult in
          switch (encodingResult) {
          case .success(let value):
            completionHandler(APIResult.success(value))
          case .failure(let error):
            completionHandler(APIResult.failure(error))
          }
        }
      )
  
  }
  </code></pre>