Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AngularJS issue 13374
<!DOCTYPE html>
<script src=""></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' });
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);
<body ng-app="app">
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