Fehler beim laden von PDF-Dokument - Angular JS - BLOB

Ich versuche, PDF-Dokument aus Web-API, und wollen zeigen, in Eckige App. Immer "Failed to load PDF-Dokument Fehler".
Ich habe
"AngularJS: Anzeige von blob - (.pdf) in einem Winkelbereich app" post.
In der Erwägung, runterladen kann ich die gleiche Datei erfolgreich von folgenden "Download-Datei von einem ASP.NET Web-API-Methode unter Verwendung von AngularJS" post.

Sieht aus wie ich immer bin, die Datei als "Chunked Transfer Verschlüsselt". Irgendwie ist das nicht immer entschlüsselt, wenn Sie versuchen zu zeigen, in eckige app. Bitte beraten.

Web-API-Code:

HttpResponseMessage result = null;
        var localFilePath = @"C:\Test.pdf";

        if (!File.Exists(localFilePath))
        {
            result = Request.CreateResponse(HttpStatusCode.Gone);
        }
        else
        {//serve the file to the client
            result = Request.CreateResponse(HttpStatusCode.OK);
            result.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));                
            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
            result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
            result.Content.Headers.ContentDisposition.FileName = "Test.pdf";
            result.Content.Headers.Add("x-filename", "Test.pdf");
        }

        return result;

Winkel-Controller:

   myModule.controller("pdfviewerController", function ($scope, $http, $log, $sce) {
$http.post('/api/Sample/GetTestFile', {responseType:'arraybuffer'})
 .success(function (response) {      
  var file = new Blob([response], { type: 'application/pdf' });
  var fileURL = URL.createObjectURL(file);
  $scope.content = $sce.trustAsResourceUrl(fileURL);            
 });
});

HTML-Template:

<embed ng-src="{{content}}" style="width:200px;height:200px;"></embed>

InformationsquelleAutor Mahesh Pulle | 2015-01-22

Schreibe einen Kommentar