我试图从Web API获取PDF文档,并希望在Angular App中显示 . 获得"Failed to load PDF document error" . 我已经关注了“AngularJS: Display blob (.pdf) in an angular app " post. Whereas, i can download the same file successfully by following " Download file from an ASP.NET Web API method using AngularJS”的帖子 .
看起来我得到的文件是“Chunked Transfer Encoded” . 不知何故,当试图在角度应用程序中显示时,这不会被解码 . 请指教 .
Web API代码:
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