title: Upload image to server - Swift 3
body: <p>I want to send an image as a parameter along with my request. 
  I have used the code below to call my POST request but I don't know how to append image to the body.</p>
  
  <p>I am getting the image through image picker as follows:</p>
  
  <pre><code>if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
  </code></pre>
  
  <p>My request is formed as below</p>
  
  <pre><code>var request = URLRequest(url: URL(string: "")!) // link removed
          request.httpMethod = "POST"
          let postString = "user_id=\(userId)&amp;image=\(image)"
          request.httpBody = postString.data(using:.utf8)
  
          let task = URLSession.shared.dataTask(with: request) { data, response, error in
              guard let data = data, error == nil else {               // check for fundamental networking error
                  return
              }
              do {
                  let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? AnyObject
  
                  if let parseJSON = json {
                      print("resp :\(parseJSON)")
                  }
              } catch let error as NSError {
                  print("error : \(error)")
              }
          }
          task.resume()
  </code></pre>
  
  <p>I am new to Swift. I have seen this through multipart/form-data but unable to implement it myself. I do not want to encode it in base 64 format. Please help me in this.</p>