angularjs - Failed to load PDF document - Angular JS - BLOB -
I am trying to get the PDF document from the web API, and want to show it in the Koner app. "Failed to load pdf document error" I have followed the "post" while I can successfully download the same file by following the post.
It seems that I am getting the file as "Chunked Transfer Encoded". While trying to show in angular app it is not being decoded in any way. Please advise.
Web API Code:
HTPRPSpension Message Result = Faucet; Var localFilePath = @ "C: \ Test.pdf"; If (! File Expert (Local FilePath)) {Results = Request Creteresons (HTTTPTAS code.Gone); } Else {// Client's result in file = service = request. CreteSpons (HTTTPTAS code.OK); Result. Resource = New Stream Content (New File Stream (Local File Path, Filemod. Open, FileAccess. Read); Results: music. Header. Content Disposition = New System met. Hpp Header. Content Disposition Header Value ("Attachment"); Results: music. Header. Content Type = New MediaTapheader Value ("App / PDF"); Content. Content. Header. Content dispute. Filename = "test pdf"; Consequences. Header. Add ("x-filename", "test pdf"); } Return results; angular controller:
myModule.controller ("pdfviewerController", function ($ radius, $ http, $ log, $ sce) {$ http post (File type = 'application / PDF'}); var fileURL = '' URL.createObjectURL (file); $ scope.content = $ sce.trustAsResourceUrl (fileURL);});}); HTML Template:
& lt; Embed ng- src = "{{content}}" style = "width: 200px; height: 200px;" & Gt; & Lt; / Embed & gt;
The problem is in the controller {responseType: 'arraybuffer'} Very important for $ http.get - this should be the second parameter. $ http.post - This should be the third parameter.
In the above case, I am using $ http.post and I have the {responseType: 'arraybuffer'} as the second parameter.
$ http.post ('/ api / sample / gatestuff file', {responseType: 'arraybuffer'})
correct code
< P> $ http.post ('/ api / sample / gatestest file', '', {responseType: 'arraybuffer'})
Comments
Post a Comment