How to Display blob (.pdf) in an AngularJS app

后端 未结 8 1381
逝去的感伤
逝去的感伤 2020-11-22 11:01

I have been trying to display pdf file which I am getting as a blob from a $http.post response. The pdf must be displayed within the app using

8条回答
  •  [愿得一人]
    2020-11-22 11:50

    Adding responseType to the request that is made from angular is indeed the solution, but for me it didn't work until I've set responseType to blob, not to arrayBuffer. The code is self explanatory:

        $http({
                method : 'GET',
                url : 'api/paperAttachments/download/' + id,
                responseType: "blob"
            }).then(function successCallback(response) {
                console.log(response);
                 var blob = new Blob([response.data]);
                 FileSaver.saveAs(blob, getFileNameFromHttpResponse(response));
            }, function errorCallback(response) {   
            });
    

提交回复
热议问题