jac*_*ick 3 .net azure asp.net-core
通过作为 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);
}
Run Code Online (Sandbox Code Playgroud)
我相信我的问题只是请求花费的时间太长,Azure 正在取消它以保持应用程序的完整性。从我的研究来看,这听起来也像是我需要允许应用程序启动 Azure 上传并将其添加到数据库中。然而,从我在本地的测试来看,这个过程的漫长部分甚至在我到达我的控制器的任何逻辑之前。有一个更好的方法吗?
如果您通过 IIS 托管您的 .net 核心应用程序,您仍然可以将 web.config 文件添加到您的应用程序的根目录。当您在上传较大的文件时出现超时或 404 错误时,很可能是 maxAllowedContentLength 问题。
有一些很好的答案在这里可以更详细地描述这一点。
如果您使用 IIS 托管,简短的回答是将其添加到您的 web.config 文件中。
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" /> <!--50MB-->
</requestFiltering>
</security>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1147 次 |
| 最近记录: |