【发布时间】:2019-01-14 05:25:33
【问题描述】:
以前我从 ASP.net core 2.0 以Byte array 发送文件,在 Angular 4 应用程序中我调用下面的函数来下载文件
function (response) { // Here response is byte array
var url= window.URL.createObjectURL(res);
var link = document.createElement("a");
link.setAttribute("href", url);
link.setAttribute("download", this.zipLocation + ".zip");
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
但现在我想从服务器发送文件路径,如下所示
https://websiteaddress/file/path/to/download.ext
所以在 Angular 5 中,我可以直接将链接附加到锚标记的 href 属性,并自动点击它。所以我不需要将字节数组转换为url
这里的问题是我不知道如何使用 ASP.net 核心创建可下载的文件路径并将其发送到前端
我也想知道,发送Byte array 还是Sending the direct link 哪种方法更好?两者是否存在性能问题?
【问题讨论】:
标签: c# download .net-core asp.net-core-2.0 asp.net-core-webapi