【发布时间】:2018-08-18 01:50:51
【问题描述】:
我将文件存储在 Openstack Swift 容器(对象存储)中。我通常通过 API 访问它们,如下所示:
_oApi.Swift.GetObject(containerName, fileName, outputStream);
现在,我有一个用 ASP NET Core 2.0 编写的 Web 界面,我希望用户能够下载存储在 Swift 容器中的文件。
以下代码有一个缺点,文件首先下载到我的网络服务器,然后才会在客户端开始下载。
[HttpGet]
public IActionResult Download(string id)
{
Response.Headers.Add("Content-Disposition", $"attachment; filename={fileName}");
Response.Headers.Add("Content-Length", filseSize);
Response.Headers.Add("Content-Type", "application/octet-stream");
_oApi.Swift.GetObject(containerName, fileName, Response.Body);
return View();
}
如何在不将结果缓存在网络服务器上的情况下将下载直接流式传输到客户端浏览器?
PS:我正在尝试使用 20mb 或更大的文件,因为此代码适用于小文件。
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc openstack-swift