Skip to content

Instantly share code, notes, and snippets.

@petebacondarwin
Created November 25, 2015 10:21
Show Gist options
  • Save petebacondarwin/08cc302be510de670c67 to your computer and use it in GitHub Desktop.
Save petebacondarwin/08cc302be510de670c67 to your computer and use it in GitHub Desktop.
AngularJS issue 13374
<!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>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment