java pdf无法加载_无法加载PDF文档 - Angular JS - BLOB

在尝试从Web API获取PDF并在Angular应用中显示时遇到问题,显示'Failed to load PDF document'错误。尽管可以成功下载文件,但Angular应用中显示时文件未正确解码,可能由于'Chunked Transfer Encoded'导致。文中提供了Web API代码和Angular控制器的示例,并寻求解决方法。
摘要由CSDN通过智能技术生成

我试图从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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值