title: Convert base64 to image file in AngularJS
body: <p>I'm using <a href="https://github.com/alexk111/ngImgCrop" rel="nofollow">ngImgCrop</a> plugin for image crop and post to my rest service. HTML like this:</p>
  
  <pre><code>&lt;form&gt;
            &lt;button class="btn btn-default fileUpload" type="submit"&gt;&lt;span&gt;from pc&lt;/span&gt;
              &lt;input type="file"
                     id="fileInput"
                     class="upload"
                     onchange="angular.element(this).scope().uploadFile(this.files[0])"/&gt;&lt;/button&gt;
            &lt;button class="btn btn-default" type="submit"&gt;from camera&lt;/button&gt;
  
            &lt;div class="cropArea"&gt;
              &lt;img-crop image="image.myImage" result-image="image.myCroppedImage"&gt;&lt;/img-crop&gt;
            &lt;/div&gt;
            &lt;div class="hidden"&gt;&lt;img ng-src="{{image.myCroppedImage}}" ng-model="updatedPhoto" /&gt;&lt;/div&gt;
            &lt;div class="modal-footer"&gt;
              &lt;button type="button" class="btn btn-default" data-dismiss="modal" ng-click="closeThisDialog(value)"&gt;Close
              &lt;/button&gt;
              &lt;button type="submit" ng-click="updatePhoto()" class="btn btn-primary"&gt;Save&lt;/button&gt;
          &lt;/form&gt;
  </code></pre>
  
  <p>And controller.js:</p>
  
  <pre><code>$scope.updatePhoto = function () {
        var updatedPhotoLink = {
        file: file
      };
        $http({
          method: 'POST',
          data:  updatedPhotoLink,
          url: '//myapiservices.com/upload'
        }).then(function successCallback(response) {
         console.log(response);
        }, function errorCallback(response) {
          console.log("error");
          // called asynchronously if an error occurs
          // or server returns response with an error status.
        });
      }
  </code></pre>
  
  <p>Yes, it works but image link return to by base64 but API link want to it by file.</p>
  
  <p>I tried to add for change this:</p>
  
  <pre><code>      var imageBase64 = $scope.image.myCroppedImage;
        var blob = new Blob([imageBase64], {type: 'image/png'});
  </code></pre>
  
  <p>But its not worked, image file return to blank. How can I convert base64 url to file? Thanks.</p>