title: How to send an image via a POST request in Swift 4?
body: <pre><code>func createPost(username: String, user_id: String, description: String, image: UIImage, completion: @escaping (Bool) -&gt; ()) {
      var request = URLRequest(url: URL(string: Globals.root+"/amazing/image/post/here")!)
      request.httpMethod = "POST"
      //request.httpBody = .data(using: .utf8)
      let task = URLSession.shared.dataTask(with: request) { data, response, error in
          if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
              print("statusCode should be 200, but is \(httpStatus.statusCode)")
              print("response = \(String(describing: response))")
          }
          if let data = data {
              do {
                  let aaData = try JSONSerialization.jsonObject(with: data, options: [])
                  if let ppData = aaData as? [String:Any] {
                      let u = ppData["username"] as! Bool
                      if u == true {
                          completion(true)
                      }
                  }
              } catch let error as NSError {
                  print(error.localizedDescription)
                  completion(false)
              }
          }
      }
      task.resume()
  }
  </code></pre>
  
  <p>I've been searching and searching for a valid answer and I haven't found any that pertains to Swift 4. I want to be able to send an image to my RESTful API without encoding it. How can one do that? Thanks in advance. : )</p>