title: How to convert captureStillImageAsynchronously(sampleBuffer) to base64 encode in Swift 3
body: <p>How to convert captureStillImageAsynchronously(sampleBuffer) to base64 encode in Swift 3</p>
  
  <p>I am trying to continuous feed image data to HTML web view, after finding ,no Cordova plugin can fit this goal, because I need the image/video data to draw on canvas so I can process it with js library.</p>
  
  <p>Initially I wanted to use WEBRTC but it is only available for android. I am developing on IOS 9+.</p>
  
  <p>Therefore I am trying to create a very simple plugin that show the preview for real time and feed the image data every .3 second(call with javascript Cordova pluging command), in order to process the image.</p>
  
  <p>The swift tutorial for getting sampleBuffer:
  <a href="http://drivecurrent.com/using-swift-and-avfoundation-to-create-a-custom-camera-view-for-an-ios-app/" rel="nofollow noreferrer">http://drivecurrent.com/using-swift-and-avfoundation-to-create-a-custom-camera-view-for-an-ios-app/</a></p>
  
  <p>The thing I need is convert captureStillImageAsynchronously sampleBuffer to base64 encode, or if there any other way to have the image data which can process by javascript?</p>
  
  <pre><code>   if let videoConnection = stillImageOutput!.connection(withMediaType: AVMediaTypeVideo) {
          videoConnection.videoOrientation = AVCaptureVideoOrientation.portrait
          stillImageOutput?.captureStillImageAsynchronously(from: videoConnection, completionHandler: {(sampleBuffer, error) in
              if (sampleBuffer != nil) {
                  let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
                  let dataProvider = CGDataProvider(data: imageData as! CFData)
                  let cgImageRef = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: CGColorRenderingIntent.defaultIntent)
  
                  let image = UIImage(cgImage: cgImageRef!, scale: 1.0, orientation: UIImageOrientation.right)
                  self.capturedImage.image = image
                  print(sampleBuffer) // how to convert this to 64encode ? without saving to camera roll
              }
          })
      }
  </code></pre>