i have hyperlink in my ui grid where user can click to send request to server and server will return html/pdf file as byte array to UI. Here, i have to display that byte array in modal window using angularjs and i am not getting any idea how do i display it. i have tried( AngularJS: Display blob (.pdf) in an angular app) below url solution but did not work for me. any help will be appreciated.
FileSerivce.js:
function FileSerivce($http,$sce) {
return {
viewFile : viewFile,
};
function viewFile(key) {
return $http.get('../test/getFile?key='+ key,{responseType:'arraybuffer'}).then(
viewFileComplete)["catch"](viewFileFailed);
function viewFileComplete(response) {
console.log("viewFile data received from service : ",response.data);
return response.data;
}
function viewFileFailed(error) {
console.error('XHR Failed viewFile.', error.data);
}
}
}
FileController.js:
function FileController($scope, $filter, uiGridConstants, $location, $anchorScroll, FileSerivce, $sce,$window) {
$scope.getFile= function(key){
FileSerivce.viewFile(key).then(function(data){
var file = new Blob([(data)], {type: 'text/html'});
var fileURL = URL.createObjectURL(file);
$scope.corrPreviewData = $sce.trustAsResourceUrl(fileURL);
});
}
}