【发布时间】:2020-12-03 08:30:07
【问题描述】:
我正在尝试将文件保存到客户端的机器上。我想要求客户端选择下载位置。
我有 REST 服务的端点,它返回要下载的文件。我正在尝试设置代码以使用另存为对话框下载从服务返回的文件。
var Url = "https://randomaddresss/v5/invoices/{" + InvoicesId + "}/getpdfbyid";
HttpResponse response = HttpContext.Current.Response;
response.ClearContent();
response.Clear();
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "attachment; filename=" + InvoicesId + ".pdf;");
response.TransmitFile(Url);
response.Flush();
response.End();
返回的错误在response.TransmitFile(Url);这一行:
'https://randomaddresss/v5/invoices/2131231231231312/getpdfbyid' 不是有效的虚拟路径。
【问题讨论】:
-
我假设您的应用程序是一个网站? TransmitFile 是将文件从服务器的文件系统传输到客户端,而不是从 url
-
是的,没错,我的应用是一个网站。
-
我会说你可以从内存中的其余 api 加载文件并将流传递给你的客户端
标签: c# api rest asp.net-web-api