我有一个带有ASP.Net Web API的angular2项目。我有代码从我的数据库检索到我的服务器上的文档的文件路径。然后我想在浏览器中的新标签中显示这个文档。有没有人有任何建议如何做到这一点?Angular2显示PDF
我很高兴能够检索Angular2(Typescript)或我的API中的文件并将其流式传输。
这是我在我的API检索它的尝试,但我不能工作,如何接受它Angular2并正确显示:
public HttpResponseMessage GetSOP(string partnum, string description)
{
var sopPath = _uow.EpicorService.GetSOP(partnum, description).Path;
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(sopPath, FileMode.Open);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");
return result;
}
任何帮助将不胜感激。
很多谢谢!
如果您想在另一个选项卡中看到它,为什么不直接打开API的新选项卡并让浏览器解释内容?您可能需要使用MIME类型的“application/pdf”而不是“application/octet-stream”。 – LinuxDisciple
我写了关于获取和显示在Angular 2中的新选项卡中的pdf文件,请查看我的答案:http://stackoverflow.com/questions/37046133/pdf-blob-is-not-showing-content-angular-2/ 39657478#39657478 –
@StefanSvrkota会这样使用我的API,因为它是?或者,我需要进行更改才能以正确的格式返回它? – DaRoGa