我有一个控制器操作,它读取.pdf
从 azure blob 存储中读取文件并将流对象返回到$.ajax()
method.
控制器返回
var stream = blobStorage.OpenRead(filepath);
await FileAsync(stream, "application/pdf");
Ajax 调用和响应
$.ajax({
type: "POST",
url: "/PDFfile",
data: { 'id': Id },
dataType: "application/pdf",
traditional: true,
complete: function(data) {
var w = window.open("data:application/pdf, " + escape(data.responseText));
w.document.write(data.responseText);
w.document.close();
}
});
但是,如果调用的是如图所示的同一控制器操作,则文件将正确显示。
<a class="pull-right btn-link" target="_blank" data-bind="attr: { href: '/PDFfile/' + Id }"></a>
It may appear as a duplicate question but none of the solutions worked for me.
The output I am getting is as shown.
我找不到这个问题的确切答案。我发现了一堆不同的问题。
我终于能够通过使用拼凑起来fetch
。
您需要接受类型'arraybuffer'
,然后你变成一个斑点resopnse.blob()
。然后您可以在新窗口中打开该 blob。
fetch('/post/url', {
method: 'POST',
headers: {
Accept: 'arraybuffer',
'Content-Type': 'application/json',
},
//you need to use json here
body: JSON.stringify({ items: [{ ItemId: 3, Quantity: 40 }], fileId: 2 });
})
.then(response => response.blob())
.then(data => {
var popup = window.open(URL.createObjectURL(data), "height=500,width=750);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)