title: Unable to successfully Encode UIImage and store in Database
body: <p>I'm looking to convert a UIImage to NSData (this part works), then encode that NSData into a string so that I can store into my database through an Alamofire POST request.<br>
  Here is the code I have so far and the different encoding methods I have tried in Swift 2:</p>
  
  <pre><code>let a = spaceImage.image
  let imageData = UIImagePNGRepresentation(a!)
  
  //First method
  let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
  
  //Second method
  let base64String2 = imageData!.base64EncodedStringWithOptions(NSDataBase64EncodingOptions(rawValue: 0))
  
  //Third method
  let base64String3 = String(data: imageData!, encoding: NSUTF8StringEncoding)
  </code></pre>
  
  <p>So there was a specific issue with each of these methods.</p>
  
  <p>First Method, I get this error:</p>
  
  <blockquote>
    <p>FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}</p>
  </blockquote>
  
  <p>Second Method, I get the same error as the first method:</p>
  
  <blockquote>
    <p>FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}</p>
  </blockquote>
  
  <p>Third Method, When I print this string, it is nil so that is clearly not working either.</p>
  
  <p>Keep in mind, I am using Swift 2 and Alamofire to make the POST requests (encoding in JSON). What is the correct way to achieve what I am trying to do?</p>