starter.directive('httpSrc', function ($http, global) { return { restrict: "A", link: function (scope, element, attrs) { var requestConfig = { method: 'GET', responseType: 'arraybuffer', cache: 'true' }; function base64Img(data) { var arr = new Uint8Array(data); var raw = ''; var i, j, subArray, chunk = 5000; for (i = 0, j = arr.length; i < j; i += chunk) { subArray = arr.subarray(i, i + chunk); raw += String.fromCharCode.apply(null, subArray); } return btoa(raw); }; attrs.$observe('httpSrc', function (newValue) { requestConfig.url = newValue; global.fetch_user().then(function () { $http(requestConfig).then(function (data) { attrs.$set('src', "data:image/jpeg;base64," + base64Img(data.data)); }); }); }); } } })