Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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);
    });
}

}

share|improve this question
    
are you getting data back? if so, is it binary? – icfantv Dec 11 at 19:46
    
yea i am getting data as byte 64 binary. – user4181313 Dec 21 at 19:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.