javascript - blob shows up as bytestring ( angular + express ) -


i trying pull files back-end node.js / express server , display them in angular front-end. have tried different approaches keep on being stuck, data @ front-end displayed bytestring displaying base64 string didn't (it displayed base64 string).

i think caused not setting properties of window use show file.

my express code:

router.get('/api/v1/getupload/:filename', function(req,res){     res.sendfile(__dirname + '/uploads/' + req.params.filename); }); 

my angular service code:

(the managedatafactory returns result of call express)

//get uploaded file $scope.getuploadfile = function(file) {     // data link pdf     managedatafactory.getuploadfile(file, {responsetype:'arraybuffer'}).success(function(f){         var blob = new blob([f]);         var fileurl = $window.url.createobjecturl(blob);         $scope.content = $sce.trustasresourceurl(fileurl);         var w = $window;         w.open($scope.content);     }); } 

the html contains call ng-click correct filename.

this result of call back-end (the newly opened window shows pretty same):

`�png  ��� ihdr����������    �����srgb@�}����    phys�������+���textsoftware�microsoft office�5q����idatx����t������>���j�@hb�����bp���� etcetcetc` 

the result can either pdf or image, have cater both. appreciated have been stuck on issue time , starting losing hair on it.

in end, replaced angular post simple , resolves everything.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -