title: Multipart upload with request parameters and headers (Alamofire)
body: <p>I'm trying to upload a photo on the server and I have to set the request headers and parameters.</p>
  
  <p>In postman the request looks like image below:
  <a href="https://i.stack.imgur.com/p5746.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/p5746.png" alt="enter image description here"></a></p>
  
  <p>I don't know how to set first key "scan".
  I tried to set for the scan key the image local path, the image size but without result.</p>
  
  <p>I tried in this way to upload the image on server :</p>
  
  <pre><code>       Alamofire.upload(multipartFormData: { (multipartFormData) in
          for (key, value) in params {
              multipartFormData.append("\(value)".data(using: String.Encoding.utf8)!, withName: key as String)
          }
  
          if let data = imageData{
              multipartFormData.append(data,  withName: "image", fileName: "image.png", mimeType: "image/png")
          }   
      }, usingThreshold: UInt64.init(), to: ApiClientURLs.photo, method: .post, headers: headers) { (result) in
          switch result {
          case .success(let upload, _, _):
  
              upload.uploadProgress(closure: { (Progress) in
                  print("Upload Progress: \(Progress.fractionCompleted)")
              })
  
              upload.responseJSON { response in
                  //self.delegate?.showSuccessAlert()
                  print(response.request)  // original URL request
                  print(response.response) // URL response
                  print(response.data)     // server data
                  print(response.result)   // result of response serialization
                  //                        self.showSuccesAlert()
                  //self.removeImage("frame", fileExtension: "txt")
                  if let JSON = response.result.value {
                      print("JSON: \(JSON)")
                  }
              }
  
          case .failure(let encodingError):
              //self.delegate?.showFailAlert()
              print(encodingError)
          }
      }
  </code></pre>
  
  <p>Colleagues from the server side told me that it's a problem with the multipart upload and sent me this error:</p>
  
  <pre><code>default message [scan]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'org.springframework.web.multipart.MultipartFile' for property 'scan'
  </code></pre>
  
  <p>The headers and parameters request looks like:</p>
  
  <pre><code>      let headers: HTTPHeaders = [
          "Content-type" : "multipart/form-data",
          "X-Email"      : decodedLoginModel.email ?? "",
          "Token"        : decodedLoginModel.jwt ?? ""]    
  
      var params: [String: Any] =  [
          //"scan" : imagePath
          "contact_email": contact_email_switch,
          "contact_mail": contact_mail_switch,
          "contact_phone": contact_phone_switch,
          "contact_sms": contact_sms_switch,
          "required_id": Int.random(in:1111...1999) ]
  </code></pre>
  
  <p>Can you help me to fix the upload ?</p>