title: Swift 3.1 How to insert image as base64 into body of HTTPS request
body: <p>I want to send an image to server using HTTPS POST request. I need to send image as base64 data. I have converted image data to base64 encoded string, but I cannot convert it to Data to put it into httpBody.</p>
  
  <pre><code>    //encode image to base64
      let chosenImage = imageView.image
      let imageData:NSData = UIImagePNGRepresentation(chosenImage!)! as NSData
      let strBase64 = imageData.base64EncodedString(options: .lineLength64Characters)
      let dataBase64: Data = Data(strBase64)
  
  
      let uploadUrlString = "https://api.imgur.com/3/upload"
      let uploadUrl = NSURL(string: uploadUrlString)
      let uploadRequest = NSMutableURLRequest(url: uploadUrl! as URL)
      uploadRequest.addValue("Client-ID f7e5521d5dd4245", forHTTPHeaderField: "Authorization")
      uploadRequest.httpMethod = "POST"
      uploadRequest.httpBody = imageData
      let uploadSession = URLSession.shared
      let postRequest = uploadSession.dataTask(with: uploadRequest as URLRequest) { (data, response, error) -&gt; Void in
          if let antwort = response as? HTTPURLResponse {
              let code = antwort.statusCode
              print(code)
          }
      }
      postRequest.resume()
  </code></pre>
  
  <p>Saw some solutions on StakOverflow, but didn't get how to do it properly.
  Please advise.</p>