title: How to append array in multipart form data with Alamofire?
body: <p>I am uploading image with multipart form data using Alamofire but getting some problem while i am passing an array as parameter.
  <a href="https://i.stack.imgur.com/uExll.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uExll.png" alt="This is postman request"></a></p>
  
  <p>As per request i need to pass all data into letter.
  Here is how i am doing.</p>
  
  <pre><code>    let data = try! JSONSerialization.data(withJSONObject: arrSelectedRecipientsID, options: .prettyPrinted)
      let jsonString = String(data: data, encoding: .utf8)!
  
      let paramArr : [String : Any] = [
          "message" : txtvwMessage.text!,
          "status": "draft",
          "recipient_ids": jsonString
      ]
  
      let parameter  : [String : Any] = ["letter" : paramArr]
  
      let accesstoken = Utilities.retriveValueFromDefault(forKey: UDKey.kUserAuthentication_Token) as String
      let client = Utilities.retriveValueFromDefault(forKey: UDKey.kUserClient) as String
      let uid = Utilities.retriveValueFromDefault(forKey: UDKey.kUserUID) as String
  
  
      let headersInfo : HTTPHeaders = [ "Content-Type" : "multipart/form-data",
                                        "Accept" : "application/json",
                                        "access-token" : accesstoken,
                                        "client" : client,
                                        "uid" : uid
      ]
  
  
      fileUploadWithParameter(Constant.ServerAPI.kPostLetters, images: letterImage, header: headersInfo, parameters: parameter, success: { (response) in
  
          print(response)
      }) { (progress) in
  
  
      }
  </code></pre>
  
  <p>Here is Alamofire request method.</p>
  
  <pre><code>func fileUploadWithParameter(_ url: String,images:NSMutableArray,header : [String : String], parameters: [String:Any], success:@escaping (NSDictionary)-&gt;(),progressHandler:@escaping(_ progress: Double)-&gt;Void) {
  
      Alamofire.upload(multipartFormData: { multipartFormData in
          for i in 0..&lt;images.count {
  
              let rotatedImage = images[i] as! UIImage
  
              if let imgData = UIImageJPEGRepresentation(rotatedImage, 0.8) {
                  multipartFormData.append(imgData, withName: "letter[photos]",fileName: "0\(i).jpg", mimeType: "image/jpg")
              }
          }
          for (key, value) in parameters {
  
              //multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key )
              let paramsData:Data = NSKeyedArchiver.archivedData(withRootObject: value)
              multipartFormData.append(paramsData, withName: key)
  
          }
  
      }, to: url,
         method:.post,
         headers:header) { (result) in
          print("\n\n\nRequest URL :- \(url)\nParameters :- \(parameters)")
          switch result {
          case .success(let upload, _, _):
  
              upload.responseJSON { response in
  
                  if response.error != nil {
                      print("Error :- \((response.error?.localizedDescription)!)\n\n\n")
                  }
                  if let jsonDict = response.result.value as? NSDictionary {
                      print("Response :- \(jsonDict)\n\n\n")
  
                  } else {
                      print("Error :- \(Constant.ErrorMessage.kCommanError)\n\n\n")
  
                  }
              }
          case .failure(let encodingError):
              print("Error :- \(encodingError.localizedDescription)\n\n\n")
  
          }
  
      }
  }
  </code></pre>
  
  <p>Postman works well so can someone please help me where i am doing wrong.</p>
  
  <p>API expected The proper json should be</p>
  
  <pre><code> {
     "letter":
            {
              "message": "Type your message here...!!!",
              "recipient_ids": [183, 184],
              "status": "draft"
            }
   }
  </code></pre>
  
  <p>API is in ruby on rails and it says i am sending string. Please help me to find out what is issue.  </p>