Reputation: 21406
I am returning an array of bytes from a web api method that sets content-type as 'application/octet-stream. This array of bytes is for a pdf file. I am using angularjs.
Question : What will be the data value for href in code below for this case? I have set its as attachment/pdf which is not working.
return reportsDataService.getMyData()
.then(function (data) {
var element = angular.element('<a/>');
element.attr({
href: 'data:attachment/pdf,' + url,
target: '_blank',
download: 'myreport.pdf'
})[0].click();
});
Upvotes: 1
Views: 745
Reputation: 5270
Per Blob documentation, you can code as below
var blob = new Blob([typedArray], {type: 'application/octet-binary'});
$scope.url= URL.createObjectURL(blob);
Then in your view
<a download="content.txt" ng-href="{{ url }}">download</a>
Last but not least, you should configure the compileProvider
to enable the url
app.config(['$compileProvider',
function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|ftp|mailto|tel|file|blob):/);
}]);
Upvotes: 1