Created
November 25, 2015 10:21
-
-
Save petebacondarwin/08cc302be510de670c67 to your computer and use it in GitHub Desktop.
AngularJS issue 13374
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://code.angularjs.org/1.4.8/angular.js"></script> | |
<script type="text/javascript"> | |
angular.module('app', []) | |
.run(function($http, $log) { | |
var _url = 'test.pdf'; | |
var _config = { | |
responseType: 'arraybuffer' | |
}; | |
var success = function (data, status, header, config) { | |
$log.debug('Download resume success ', data); | |
var _contentType = header('Content-Type'); | |
_contentType = _contentType.substring(0,_contentType.indexOf(";")); | |
var blob = new Blob([data], {type: _contentType}); | |
var url = (window.URL || window.webkitURL).createObjectURL(blob); | |
var anchor = angular.element('<a></a>'); | |
anchor.attr({ href: url, target: '_blank', download: 'test.pdf' }); | |
anchor[0].click(); | |
}; | |
var error = function (e) { | |
if(e != null) { | |
bootbox.alert('Error encountered when downloading resume '); | |
$log.debug('Downloading error ' + JSON.stringify(e)); | |
} | |
}; | |
$http.get(_url, _config).success(success).error(error); | |
}); | |
</script> | |
</head> | |
<body ng-app="app"> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment