我正在尝试下载文件,但是我收到HTTP错误502.3,问题是我正在压缩的文件夹太大(300 MB)。拉链尚未完成拉链。因此错误
我也累了没有等待Task.Run:像这样:
ZipFile.CreateFromDirectory($"{tempFolder}\\somefolder", $"tempFolder}\\somefolder.zip");
任何想法/提示?
感谢' S
public async Task<IActionResult> DownloadFileAsync()
{
string tempFolder = this.hostingEnvironment.WebRootPath + $"\\temp\\";
#region Zip and delete Folder
await Task.Run(() => ZipFile.CreateFromDirectory($"{tempFolder}\\somefolder", $"{tempFolder}\\somefolder.zip")); // zip the big folder
if (Directory.Exists($"{tempFolder}\\somefolder"))
{
try
{
Directory.Delete($"{tempFolder}\\somefolder", true);
}
catch (Exception)
{
throw new Exception($"Failed to delete {$"{tempFolder}\\somefolder"}");
}
}
#endregion Zip and delete Folder
var memory = new MemoryStream();
using (var stream = new FileStream($"{tempFolder}\\somefolder.zip", FileMode.Open))
{
await stream.CopyToAsync(memory);
}
memory.Position = 0;
return File(memory, "application/zip", $"somefolder.zip");
}
答案 0 :(得分:0)
所以这是一个超时问题:
https://github.com/aspnet/AspNetCoreModule/issues/48
增加20分钟的时间:)
<system.webServer>
<aspNetCore requestTimeout="00:20:00" ... />
</system.webServer>