javascript - BLOB object is not visible -
actually, trying image using $http , storing data in blob object can use after on
html
<body ng-app="myapp"> <div ng-controller="homectrl"> <button ng-click="download()">download</button> <img id="photo"/> </div>
controller:
angular.module('myapp', []); angular.module('myapp').controller('homectrl', ['$scope', '$http', function($scope, $http) { $scope.download=function() { $http.get('https://placeholdit.imgix.net/~text?txtsize=15&txt=image1&w=120&h=120').success(function(data){ var arraybufferview = new uint8array( data ); var blob = new blob( [ arraybufferview ], { type: "image/png" } ); var urlcreator = window.url || window.webkiturl; var imageurl = urlcreator.createobjecturl( blob ); var img = document.queryselector( "#photo" ); img.src = imageurl; }).error(function(err, status){}) } }]);
plunker same problem:http://plnkr.co/edit/4kfksigcudilwoas2vsz?p=preview
you need set responsetype "arraybuffer"
$http.get('https://placeholdit.imgix.net/~text?txtsize=15&txt=image1&w=120&h=120', {responsetype: "arraybuffer"})
Comments
Post a Comment