title: Ionic - How to create Image Blob from cordovaImagePicker.getPictures ImagePicker for S3
body: <p>Using ionic,
  I am trying to create an image blob from URI and have tried several codes but failed.</p>
  
  <p>Here is where I implement the imagepicker in ionic:</p>
  
  <pre><code>  $cordovaImagePicker.getPictures(options)
      .then(function (results) {
  
        console.log(results[0]);
        var datablob = $scope.dataURItoBlob(results[0]);
  </code></pre>
  
  <p>technique 1 (create the blob):</p>
  
  <pre><code>  $scope.dataURItoBlob = function(dataURI) {
  
      var binary = atob(dataURI.split(',')[1]);
      var array = [];
      for (var i = 0; i &lt; binary.length; i++) {
        array.push(binary.charCodeAt(i));
      }
  
      var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
      return new Blob([new Uint8Array(array)], {
        type: mimeString
      });
  
    }    
  </code></pre>
  
  <p>technique 2 (create the blob):</p>
  
  <pre><code>  $scope.dataURItoBlob = function(dataURI) {
  
      var arr = dataURI.split(','), mime = arr[0].match(/:(.*?);/)[1],
          bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
      while(n--){
          u8arr[n] = bstr.charCodeAt(n);
      }
      return new Blob([u8arr], {type:mime});
  
    }    
  </code></pre>
  
  <p>Both techniques does not work. Please help! thank you very much.</p>