【发布时间】:2016-04-26 15:04:04
【问题描述】:
这是我的 Web API 2 控制器中的代码:
//pdfBytes is a valid set of...pdfBytes, how it's generated is irrelevant
Byte[] pdfBytes = pdfConverter.GeneratePdf(myPdfString);
//using HttpResponseMessage instead of IHttpActionResult here because I read
//that the latter can cause problems in this scenario
var response = new HttpResponseMessage();
//Set reponse content to my PDF bytes
response.Content = new ByteArrayContent(pdfBytes);
//Specify content type as PDF - not sure if this is necessary
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
return response;
在客户端收到 PDF 后,如何触发浏览器自动下载 PDF 或在新窗口中打开? (注意 - 我不确定字节数组是否是我想要在这里接收的格式)。
callToGetPdfFromDb()
.success(function (pdfFromWebApi) {
console.log('Got pdf...'');
//How do I show the received PDF to the user?
});
我对处理任何类型的文件下载/上传都很陌生,所以如果我遗漏了一些非常基本的东西,我深表歉意。作为回应,我对正确方向的指针非常满意。
【问题讨论】:
标签: javascript c# angularjs pdf asp.net-web-api2