title: Send image as base64 string through web service
body: <p>I have an app allow user upload a photo from photo library, first the app convert the image to base64 string and then pass the string to server through web service (C#.net).</p>
  
  <p>Finally it is only work on some simple photos (e.g. black &amp; white photos, small photos) but failed if color photos, I am not sure but i guess the base64 string truncated when passing to web server. (May be the string too long). Is it any problem on my code below?</p>
  
  <pre><code>func UploadPhoto(img: UIImage){
      let strBase64 = img.jpegData(compressionQuality: 1)?.base64EncodedString() ?? ""
  
      var request = URLRequest(url: URL(string: "https://xxxxx/uploadimg.asmx/UploadFile")!)
      request.httpMethod = "POST"
  
      let postString = "Base64String=" + strBase64
  
      request.httpBody = postString.data(using: .utf8)
  
      let task = URLSession.shared.dataTask(with: request)
      {
          data, response, error in
  
          if error == nil &amp;&amp; data!.count &gt; 0, let _ = data {
              do
              {
                  print ("API UploadFile Finished")
              }
              catch let error as NSError
              {
                  print("UploadFile error")
                  print(error)
              }
          }
      }
      task.resume()
  }
  </code></pre>