title: send multi part form data in swift
body: <p>I used this code below to send multipart params </p>
  
  <pre><code> let headers = [
          "Content-Type": "application/x-www-form-urlencoded",
          "Authorization": "Bearer \(myToken)",
          "cache-control": "no-cache"
      ]
  
      let parameters = [
          [
              "name": "firstname",
              "value": "alex"
          ],
          [
              "name": "lastname",
              "value": "black"
          ],
          [
              "name": "birthdate_day",
              "value": "1"
          ],
          [
              "name": "birthdate_month",
              "value": "5"
          ],
          [
              "name": "birthdate_year",
              "value": "1989"
          ],
          [
              "name": "gender",
              "value": "m"
          ],
          [
              "name": "avatar",
              "fileName": "\(imageURL)"
          ]
      ]
  
      let boundary = "Boundary-\(NSUUID().uuidString)"
  
      var body = ""
      let error: NSError? = nil
      for param in parameters {
          let paramName = param["name"]!
          body += "--\(boundary)\r\n"
          body += "Content-Disposition:form-data; name=\"\(paramName)\""
          if let filename = param["fileName"] {
              if let contentType = param["content-type"] {
              do {
                  let fileContent = try String(contentsOfFile: filename, encoding: String.Encoding.utf8)
                  if (error != nil) {
                      print(error as Any)
                  }
  
                  body += "; filename=\"\(filename)\"\r\n"
                  body += "Content-Type: \(contentType)\r\n\r\n"
                  body += fileContent
              } catch {
                  print(error)
              }
              }
          } else if let paramValue = param["value"] {
              body += "\r\n\r\n\(paramValue)"
          }
      }
  
      let postData = NSMutableData(data: body.data(using: String.Encoding.utf8)!)
  
      let request = NSMutableURLRequest(url: NSURL(string: "myUrl")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
      request.httpMethod = "POST"
      request.allHTTPHeaderFields = headers
      request.httpBody = postData as Data
  
      let session = URLSession.shared
      let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -&gt; Void in
          if (error != nil) {
              print(error as Any)
          } else {
              let httpResponse = response as? HTTPURLResponse
              print(httpResponse?.statusCode as Any)
          }
      })
  
      dataTask.resume()
      return dataTask
  </code></pre>
  
  <p>the image url and the rest of the data But I will receive Satus code 500 I know that this error is server side But the android version is using the same api url and that's working well I know that this code can be fix and maybe small changes can fix this code for working</p>