【问题标题】:Timeout when uploading file via my Azure Web App通过我的 Azure Web 应用上传文件时超时
【发布时间】:2017-06-23 22:42:15
【问题描述】:

通过托管为 Azure Web 应用程序的 .NET Core 应用程序上传文件时出现以下错误:

您要查找的资源已被删除、更改名称或暂时不可用。

这在 Postman 中进行了测试,并在 22 秒左右出现 404 Not Found 超时。

我的应用代码如下,去掉多余的东西:

    public async Task<IActionResult> PostDocuments(ICollection<IFormFile> files)
    {
        foreach (var file in files)
        {
                string path = Path.Combine(uploadsDir, file.FileName);

                //Uploading file to "uploads" to be staged. Doesn't get past here.
                using (var stream = new FileStream(Path.Combine(uploadsDir, file.FileName), FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }

                //Uploading files to Azure
                if (await _azure.UploadFile(path, file.FileName)
                {
                    // Stuff to add file to database
                }
                else
                {
                    return StatusCode(400, "Could not upload one or all of your files.");
                }
            }
            else
            {
                return StatusCode(400, "One or all of your files are empty, have invalid types, or are targeting mismatched buildings or floors.");
            }
        }

        return StatusCode(201, files);
    }

我认为我的问题只是请求花费的时间太长,Azure 正在取消它以保持应用程序的完整性。从我的研究中听起来,也许我需要允许应用程序启动 Azure 上传并将其添加到数据库中。然而,从我在本地的测试来看,这个过程的大部分时间似乎是在我到达我的控制器的任何逻辑之前。有没有更好的方法来做到这一点?

【问题讨论】:

  • 您的其他端点是否工作?例如api/foos 会返回什么吗?
  • 应用程序中的所有内容都可以正常工作,包括上传所需时间不到 22 秒的文件。
  • 您正在测试的超时文件上传有多大?有一个关于接受多大文件大小的设置。
  • 50MB。大约 10-15MB 的文件似乎可以工作。此外,当我在本地测试时,文件会上传,所以我认为它不一定是特定于应用程序的。
  • 如果您通过 IIS 托管,我会查看 this 链接以确认您的 azure Web 应用程序的设置不小于 50MB。

标签: .net azure asp.net-core


【解决方案1】:

如果您通过 IIS 托管 .net 核心应用程序,您仍然可以将 web.config 文件添加到应用程序的根目录。当您在较大的文件上传时遇到超时或 404 错误时,可能是 maxAllowedContentLength 问题。

有一些很好的答案here 更详细地描述了这一点。

如果您使用 IIS 进行托管,简短的回答是将其添加到您的 web.config 文件中。

<system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
      </requestFiltering>
    </security>
  </system.webServer>

【讨论】:

  • 我很困惑。 “Azure Web App”不是表示它不是 IIS 托管的吗?不托管 IIS 时会怎样?
猜你喜欢
  • 2021-03-09
  • 2016-05-11
  • 2016-11-14
  • 2018-02-16
  • 1970-01-01
  • 2014-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多