Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .Net core api在保存大文件时返回404_C#_.net_Asp.net Web Api_.net Core - Fatal编程技术网

C# .Net core api在保存大文件时返回404

C# .Net core api在保存大文件时返回404,c#,.net,asp.net-web-api,.net-core,C#,.net,Asp.net Web Api,.net Core,我有.NETCoreAPI,它将文件保存在文件服务器上。当文件大小很小(如10KB、1MB、10MB)时,它可以正常工作。但是,当我尝试保存100 mb的文件时,它会返回: 404-找不到文件或目录。 您正在查找的资源可能已被删除、名称已更改或暂时不可用 我已更新kestrel选项以忽略文件大小: .UseKestrel(options => { options.Limits.MaxRequestBodySize = null;

我有.NETCoreAPI,它将文件保存在文件服务器上。当文件大小很小(如10KB、1MB、10MB)时,它可以正常工作。但是,当我尝试保存100 mb的文件时,它会返回:

404-找不到文件或目录。 您正在查找的资源可能已被删除、名称已更改或暂时不可用

我已更新kestrel选项以忽略文件大小:

 .UseKestrel(options => {
                options.Limits.MaxRequestBodySize = null;

            })
文件保存代码:

using (var imageFile = new FileStream(fullPath, FileMode.Create))
            {
                imageFile.Write(bytes, 0, bytes.Length);
                imageFile.Flush();
            }
Web配置:

<system.webServer>
<security>
  <requestFiltering>
    <requestLimits maxAllowedContentLength="4294967295" />
  </requestFiltering>
</security>

但是,当托管在服务器上时,它仍然不起作用(对于大文件大小)。 尽管当我使用iis express在本地计算机上托管时,它工作正常

可能的原因是什么?或者我这里缺少的任何设置?

请检查。您需要增加/设置
maxAllowedContentLength

<system.webServer>
  <security>
    <requestFiltering>
      <!-- This will handle requests up to 50MB -->
      <requestLimits maxAllowedContentLength="52428800" />
    </requestFiltering>
  </security>
</system.webServer>


加载该文件需要多长时间?或者需要多长时间才能获得404?@Simonare:这会立即发生。@Gautam您应该根据MS文档“使用流媒体上传文件”。请参阅:我现在就是这样做的:使用(var imageFile=new FileStream(fullPath,FileMode.Create)){imageFile.Write(bytes,0,bytes.Length);imageFile.Flush();}我已经有了这样的文件: