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
%PDF-1.3
%Äåòåë§ó ÐÄÆ
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x’Í
Â0„ïyŠñ¿UˆÉÖ˜xU¼x<¨§¢AAûþà¶ö XkH ,;ßÎäŽ-î°Tnç-‚
xœ°Ã
ÓUa‘0Õ*r©3šf¯wyñï‚žäW,Y¹We}ðSfi >#é¤à Ö,rÿUÙ¨IÐkCVôÞeÊ“s4¨
`¤ÛK&éRÁ›X˜_Ó/¼vŽ|Vèʃf„Úƒa¤ªÍtk‚¦ i}{@_¨ÏF‡äFB´&oI’˜Ïå TùGÌ>Ž”mŸ=#m‚_|ÎÞ˜:¬*¿ÝäMö í枦
endstream
endobj
5 0 obj
228
endobj
2 0 obj
<< /Type /Page /Parent 3 0 R /Resources 6 0 R /Contents 4 0 R /MediaBox [0 0 595 842]
>>
endobj
6 0 obj
<< /ProcSet [ /PDF /Text ] /ColorSpace << /Cs1 7 0 R >> /Font << /TT2 9 0 R
>> >>
endobj
10 0 obj
<< /Length 11 0 R /N 3 /Alternate /DeviceRGB /Filter /FlateDecode >>
stream
x–wTSهϽ7½Ð" %ôz Ò;HQ‰I€P†„&vDF)VdTÀG‡"cE ƒ‚b× òPÆÁQDEåÝŒk ï­5óÞšýÇYßÙç·×Ùgï}׺
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment